This is a simple starter project for any BeaglePlay beginner. Just to help you get a feel for BeaglePlay and software used with it. I am living proof!
Internet Connection
I am using an ethernet cord for Internet on my BeaglePlay. You are able to use what you would like for an Internet connection. To connect to Wi-Fi, simply open the wpa_gui app and scan for your wireless network. Type the password in the "PSK" line. If the password was entered correctly, the connection should be successful.
WARNING: If you try to connect from a personal hotspot, Make sure the name does not have an apostrophe (') in it. This simple character will not let you connect to Wi-Fi because it will confuse it in the actual code itself. Trust me and save yourself the headache!
Let's Get Started:First you will connect the Capacitive Touch Slider to the Qwiic port on the BeaglePlay.
Connect your BeaglePlay to a monitor, login, and open a terminal emulator through applications in the top left corner.
Next we want to check the buses available with this command:
ls /dev/ |grep "i2c"
Now we will detect which i2c bus is connected to our Capacitive Touch slider.
You would use this command:
i2cdetect -r -y #
this is to help scan each bus to see where the Touch Slider is located. Your code will have whichever number you use to locate the bus. We are looking for the devices address, so that we may modify our own code.
As you can see below, the device address is 28 on bus 5.
**Lil Hint:When using QWIIC connector, the address will always be found in bus 5**
Now that we have the device address, Let's move on!
To begin this project, you will need to clone this repository to your project. Input this in your BP terminal. There is also a link located at the bottom of this tutorial. Name this file "CAP1203.py".
git clone https://github.com/n8many/CAP1203py.git
Once that is done, you will need to create a new file in applications. This will need to be located in your project.
Name the file whatever you would like, but I named it "slider.py".
Use the code I used below and put it in a python IDE. With BeaglePlay, I have used "Thonny". It is very easy to download. I am using python for this example.
from CAP1203py.cap1203 import CAP1203
import smbus
bus = smbus.SMBus(5) # For BeagleBoard
cap = CAP1203(bus)
while True:
res = cap.get_touched()
print(res)
# <Pad.Right: 4>
res = cap.get_touched()
print(res)
# <Pad.0: 0># True
For the SMBus, you will put 5 since this is where our device address is located.
I put a link to the original code I used below. Mine is an example.
QWIIC Capacitive Touch Slider Code
To run the file, simply type this command in your terminal.
python slider.py
Now hit space then press enter, and you're good to go!
Now you will be able to slide your finger across the pad, and the different sections will output. Examples of the output can be shown below.
Pad.0 will show if there is no interaction with the Touch Slider.
This will be the output when you slide your finger across the different sections.
How Can I expand on this?
I am so glad you asked, Let's discuss!
A fun idea I had was adding on an LED. Programming the LED to change colors depending on which region is touched. For example, the LED would flash yellow when touched in the left region. For the right region, it could flash purple. Just to add a fun twist on the example. (Check out my NodeRed + BeaglePlay project π)
Comments