Analog Inputs with your Raspberry Pi - HOW TO use the MCP3008

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi i'm nathan from py3g and today i'm going to show you how you can read analog sensors with your raspberry pi we are going to use the analog to digital converter mcp3008 let's have a look on how to wire up the adc first you need to plug the mcp3008 into the breadboard make sure that the indentation is on the top and to the left-hand side then connect 3.3 volts to the positive rail and connect any ground of your raspberry pi to the negative rail then connect the first pin of the mcp3008 to 3.3 volts and do the same with the second pin the third pin on the right side is the analog ground pin and it needs to be connected to ground the last pin on the right hand side is the digital ground pin and it needs to be connected to ground as well now we need to wire up the spi interface first we need to connect the serial clock the ninth pin from the bottom is the serial clock pin on the raspberry pi we need to connect this pin to the fourth pin of our adc then we need to connect the master in slave out pin which is right above the clock pin on the raspberry pi the next pin is the master out slave in pin again it's right above on the raspberry pi the last pin is the ground pin i'm using the ground pin right next to the clock pin of our raspberry pi and i'll connect it to the last remaining pin on the right side of our adc and with that the spi wiring is complete finally we can connect our flex sensor to the mcp3008 put the sensor into the red board and connect one of the leads to the positive rail then connect the other lead to the grounded rail and put a resistor in between i'm using a one kilo ohm resistor because i found that this works best with my sensor this circuit is called a voltage divider and now to connect the sensor we need to connect the grounded lead to the channel 0 of our ledc now that all the wires are in place we can fire up our raspberry pi to install the necessary software we need to enable the spi interface so that we can use it type the command sudo raspy minus config and then navigate to interface options spi and click yes and ok i will use the circuit python mcp3xxx library by adafruit to interface with the mcp3008 now you will find all the commands that you need in the description below first start by cloning the github repository onto your machine and then open the single ended simple test.pi example the example is meant to read one value from the channel 0 of the adc but we are going to alter the file so that it will run in a loop just add from time import sleep to the imports and then scroll all the way down until you see the print adc voltage and print raw idc value calls wrap them in a while true loop and add sleep 1 to the end of the loop then press ctrl o enter and control plus x to save and exit the file now we can finally run the python script and check if our sensor is working correctly as you can see whenever i bend the sensor the voltage goes up to 3.3 volts and when i straighten it it drops down to 0 volts so that wraps it up for today i hope you enjoyed the video and would be happy if you could leave a like also consider subscribing to our channel if you want to see more cool projects and raspberry pi how to videos click the link in the top right corner or in the description if you want to know how you can build your own sensors from scratch
Info
Channel: pi3g
Views: 16,683
Rating: undefined out of 5
Keywords: Raspberry, Pi, Raspberry Pi, ADC, MCP3008, analog, sensors, read, data, analog digital converter, analoge Sensoren, Raspberry Pi 4, HOW TO, pi3g, buyzero, PiCockpit, Python, Python3
Id: tn8sEqq0sJc
Channel Id: undefined
Length: 5min 30sec (330 seconds)
Published: Fri May 06 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.