#112
Vložit
- čas přidán 31. 05. 2018
- The Raspberry Pi (I'm using a Model 3B+) has no analog input pins at all. So how do you measure analog voltages then?
Simply connect a Microchip Analog-to-Digital-Converter (ADC) chip that uses SPI and you're in business. Just to make it really easy we can use a kit of parts from RasPiO, a UK-based company.
I have no connection with this company at all, and I didn't get the product for free or at a reduced rate.
I noticed whilst editing this video that the audio could vary as I turned from desk to soldering station; I'm already thinking of what I can do to improve this (without buying another expensive microphone). I might be able to use the built-in microphone from my video camera to augment the audio. We shall see how it works in future videos!
The sketch (OK, Python program) can be found in my Github
github.com/RalphBacon/Raspber...
Source of the Analog Zero kit
rasp.io/analogzero/
User guide for the Analog Zero kit (very useful)
rasp.io/wp-content/uploads/201...
Datasheet for the 10-bit Microchip 3008
ww1.microchip.com/downloads/en...
Datasheet for the 12-bit Microchip 3208
ww1.microchip.com/downloads/en...
VNC viewer for connecting your Windows PC to the Raspberry Pi
www.realvnc.com/en/connect/do...
---
If you like this video please give it a thumbs up, share it and if you're not already subscribed please consider doing so :)
My channel and blog are here:
------------------------------------------------------------------
/ ralphbacon
ralphbacon.blog
------------------------------------------------------------------ - Věda a technologie
Thanks Ralph, very interesting and informative
Thanks for that, Russell Moore, nice to hear from you. Hang on, is this the Russ that sold me this? I hope it helps your sales too!
thanks man, really benefited from this
Really glad that's the case, thanks for posting.
Excellent video Ralph. I found your channel looking for opto-isolators and then poked around and found this. I plan on using the MCP3008 also. And why didn't they point ADC on the PI????
And I'm glad you found me!
I dabble with the Pi, but it's too big a product (not to mention too expensive) to use in a willy-nilly fashion when compared to a £2 Arduino Uno or Nano! It can run my entire workshop automation system using Node-Red and MQTT, for goodness sake!
Yes, I think they should have included ADC on the Pi too, for an extra $1 they could have managed it. Oh well...
Thanks for the video. I've done a project with a Raspberry Pi and the MCP3008. It does its job and is very easy to work with. I'm considering the ADS1015 and the ADS1115 ADC's now, since I want to use I2C instead of SPI.
Any thoughts or experience with those two?
Yes, Martin, I did a video on the ADS1115 just a few weeks ago, it's video #104. It worked quite well but there was some noise as they were very sensitive. I used an Arduino but they will work equally well on a RasPi. I hope this helps!
That ic pin straightener is a good idea. I haven't seen one of those before.
That means you haven't watched some of my previous videos, Mike, describing essential tools 😱 but never mind, now you know and I must say I have found it indispensable over the last (cough, mumble, 30) years or so. Probably time I bought a shiny new one, actually. Thanks for posting.
Hello, very nice channel. Was wondering would this be suitable to read values from 100mV shunt or would you recommend something else?
Reading very low voltages across a shunt can bring problems in the shape of noise (it's analog). You could use a INA219 to do all this via I2C, very good chip, see it all in video #186.
@@RalphBacon Very nice. Thank you.
Excellent video, Ralph. Not a Pi person myself bu,t lets say, I was very tempted. Your example of the use of Python was very valuable for the Neophyte. Python is very easy to work with and one can get VERY sophisticated applications up and running just as fast as one likes. Being an interpreted language (i.e. no compilation needed), one can get stuff running very quickly; debugging line by line. I actually use it to develop desktop applications, then once the principles are proven, I write it all in C++. Using it, in a way, like one would use a development board to develop a circuit, then transposing the breadboard layout into a proper PCB (or vero) layout. Loved the fancy video segues .
That's an interesting way of developing a desktop app, that you describe there, Michael. Quick to develop (and debug, but you don't have any bugs, right?) and then rewrite in lower level language. Nice. Glad you liked the video, thanks for posting.
I did write a bug back in the eighties. Never again!
Brilliant video. Coming from no Arduino experience! I want to use the Resistance reading from a Wind direction vane so this kit will do nicely. But, how do I convert the readings to wind direction?
Find the limits of the resistance around the 360 degrees (eg zero to 10KΩ or 100KΩ) axis. Then _map_ the resistance (that's an Arduino function) to 360 degrees. That might mean you have set it up that North maps to 122º instead of 5º so you will need to subtract/add the required offset to get it right.
Nice project
Thanks for sharing :-)
You are most welcome Asger Vestbjerg, I'm glad you like the video. Nice to hear from you.
Great video - would I be able to plug a Resistance Level Sender into this? The type with the float which changes the resistance as the float moves up and down it?
Yes, you can. The analog inputs behave exactly as you would expect.
Awesome! I believe the sender is currently powered by a 12v power supply, could I just put a 12v - 3.3v step down in-line?
Hi actually I wanted to read 90 analog pin address using thermocouple sensor what should I do and how can I do that ?
Either Ads1115 is better or mcp3008 is better?
ADS1115 is only 4-channel AFAIK, whereas the MCP3008 is 8 channel. But to read 90 inputs is going to be a challenge. I'd do a proof of concept with just a couple of MCP3008 and make sure that all hangs together on the breadboard. Each MCP3008 requires a Chip Select pin (it's SPI driven) so you would need 90 / 8 = 12 pins to be able to select each MCP3008 in turn - best to use a MEGA2560 rather than run out of pins on an Arduino.
thank you ralph, I'm also using MCP3008 and I have 8 analogue sensors(measuring Voltage, current).
Can I get the value of this 8 at one time? if yes, How?
You will doubtless have to poll each of them in a loop, changing the I2C address (if they are I2C devices) and read the resultant value. It will only take a few milliseconds to do this, so it will appear as if you had read them simultaneously.
hi can you do a part 2 to this video and use a 0.96" I2C IIC Serial 128X64 128*64 Blue OLED LCD LED Display Module to display readings please . can you add also a bme280
I shall add your suggestion to my list and see what happens!
I am very late to this comment section, but I was wondering if there was any way to get more than 8 analog pins out of a single board, either using a different board or expanding on this one. I need 12 in total, all controlled by RPI 4. Any suggestions would be appreciated...
Have you researched daisy chaining these devices?
I'm a fan of inserting one row of ic pins in the socket, pressing against them with just slightly less pressure than it takes to collapde the pins. Then jamming the other row in place at just below light speed hoping they are lined up. I have greater than 12% success with that method! Although I imagine the pin straightener could help with recovering the failures.
I used to do it your way, Kent, before I got this pin straightener, then never looked back. They are quite cheap so I can only suggest you try one, you might prefer it and get your success rate to 99.99%! Thanks for posting.
If I need two more analog inputs, do I need two more MCP3008??
4 (MCP3004) or 8 (MCP3008) input channels (per chip).
Love your attention to detail! I have a question, being a noob to raspberry pi, transitioning from Teensy Arduino-land. Most of my Arduino code is executed via interrupt timers (never the main loop), sort of a poor man’s real time operating system. I’m hoping to write some pretty intensive code on the raspberry pi; a digital synthesizer and also some 3D rendering. I would like to know how typical raspberry pi apps handle the GPIO ports (shift registers etc) for the buttons and encoders and pots, without burdening the other SW tasks? Can a separate core for handling GPIO be setup?
Thanks in advance,
Steve
I'm afraid I am inexperienced with the Pi's way of dealing with separate cores. However, you are always at the mercy of the operating system and a hardware interrupt on an Arduino will be serviced immediately, whereas on the Pi it is whenever the OS decides that "now" is the right time - which could be several milliseconds (or more) later, depending on what the Pi is doing at the time. Same goes for Windows, of course, where you might click something and nothing happens until Windows decides to service that request (probably just at the same time you click it again in frustration). The ESP32 is a much more powerful, Arduino-compatible, dual core device but also suffers from OS "lag" to a degree.
Thanks for your reply Ralph! I know that Windows is a NOT a real time OS, ug. I take Real Time (RT) to mean deterministic interrupt timers, NOT a fast OS (as I have heard many say or assume). In my research of Raspberrian there is an option to have a RT kernel for the R-Pi. I guess I assumed that it really meant RT. Couple that with a 4 core proc and I further assumed that your could assign a core to handle the deterministic interrupt timer callbacks and GPIO HW interrupts. Hopefully this question will generate some more discussion or a good recommendation for a web source for R-Pi RT info. : - )
Thanks
Steve
Another great video, Ralph. Found this one particularly useful, thank you. It is a niggle isn't it, that the otherwise wonderful Pi, has no analogue inputs.
Glad you liked it, John, and yes, I do find it surprising they have no in-built analog ports but they are very price conscious. But the next model may have some, who knows? Glad you liked the video, thanks for posting.
Hi ralph, does this let me analyze multiple sensors at once? I mean can I observe each individual sensor's output? So one is say a pressure sensor and another a temperature sensor?
Yes you can! Each sensor can connect to a different analog input pin and you can read each pin in turn. I would prefer digital sensors that I can interrogate using I2C but that's just me!
@@RalphBacon Thanks so much for such a quick reply!
Hi Ralph, I have been watching your videos with great interest and find them facinating. I am going to be building a weather station and likely to need about 10 or so analog inputs aswell as a few digital.
Are you able to confirm if you can connect two of the Analog Zero's to the Raspberry Pi 4? I see Rasp.io do a FullpHAT so that you can connect two smaller boards like the Analog Zero, but wasn't sure if this was possible or how the RPi would know which chip select is being used? CE0 or CE1? The other question is, if i want to put another board on top of the Analog Zero, presumably if i put long pins through, i can then extend off that instead of using the side chained ports. It would be easier to have a double row of 20 for me. Thank you.
It's at about 10:40 in your video you mention the SPI port 0. I can see how to adjust the script, thats clear enough, but wasn't sure how you determine which ADC / Analog Zero ends up on which CE0 or CE1 ? Any points would be appreciated thanks. It says on Page 4 of the instructions for the Analog Zero "The Pi's SPI can handle two devices natively. If you wish to add another
SPI device, ensure its chip-select pin is connected to CE1 or it will interfere with the MCP3008 chip, which uses CE0" ?
I'm sorry to say I don't know the answer. Normally I'd at least try and find out but my workshop is all packed up pending a house move with week. I'm no expert on the Pi though, others will undoubtedly be of better help than me (just on this one occasion though!)
@@HarboroughHoney You might want to look into NODE-RED its a program on the raspberry pi. Should make your weather station much easier to build
Isn't it easier wit ARDUINO?
if we do that with ARduino , what should we do that?
An Arduino has five (sometimes 7) analogue ports already built in - the Raspberry Pi has none, hence this video!
Very nice.
remember the PCF8591 module? That works great on my raspi, but ofcourse it isn't a neat HAT, yours looks much nicer and of course more sensitive
With the 12 bits chip the reading of '2' is equal to 1.6mV. Wiring could easily have picked that up along the way
Ah, yes, the PCF8591 I2C expander module, Ed, which if I recall also works on both 3v3 and 5v. I agree that there could be noise on the wiring, it's not a deal breaker. Thanks for posting.
Ralph S Bacon Got to work with what you have and the 8 bits was enough for my needs. Nevertheless it was good finding the gpiozero library through yr video
Thank you for putting the links in your github project page. The redirected links that CZcams forces on us, in Show More, are a major pain, and frequently don't even work, due to being so convoluted. They certainly can't be copied by us into a text file, to accompany a useful video, like the ones you produce. Another way to post actual direct links is in a sticky comment.
It might even have been you, Art, that urged me to do this (if not you, then another Arduinite fan). Glad it helps and thanks for posting.
Hi Ralph. I heard you mention "From Arduino world". Can you use the analog inputs from an Arduino with a raspberry instead?
Well, you _could_ I suppose, and send the value via I2C (for example) to the Pi, but is that easier than this solution?
@@RalphBacon Being a newby to the Raspberry pi and python scripting is a very challenging task. However I managed to figure out a python script that reads the analog input connected to a potentiometer on my arduino mega 2560 and convert it to a scale of 0-180 to control a servo connected to a digital pin. I am using the Firmata protocol for the mega uploaded to my Arduino with a USB connection to my Raspberry Pi 4. The raspberry is connected to my laptop via ethernet cable. My next challenge is to figure out how to read PPM /PWM signals from a Flysky RC controller connected to my Arduino digital pins and control attached hardware like servos, motors and switches with the raspberry.
what if we need to measure more than 3v? up to 16v for example?
You need a resistor divider, or resistor ladder, so you can switch in various resistors to measure a higher voltage. Google will show you what you need.
Ralph S Bacon thank you 🙏
Hi did you try Analog input Raspberry pi with OpenPLC IDE ?
I'm afraid not, any good?
How would you use a sensor that required 5v minimum?
If a sensor is running on 5v, you can use a level shifter, a very simple device, usually bidirectional and multiple channels (4 or 8).
This will 'shift' the voltage from 5v to 3v3 (and vice versa). They are cheap and work well.
I'm using one in a current project so allow an ESP32 (3v3) to drive a NeoPixel (5v).
can i use this thing on a jetson nano?...
I'm sorry Vedprakash, I don't even know what a jetson nano is. Google may be your best friend or ask the question at forum.arduino.cc
I know this is an old video, and I presume others have said this already.
Rather than VNC I'd run two ssh sessions to the Pi. One to allow you to edit your python code and the other to run it and see the output.
That should be a great deal faster, as processing text is easier by far than processing a video stream. You shouldn't get those "freezes".
For Windows I'd run something like PuTTY. For Linux and Mac there are native ssh clients.
The downside is that you'd be using a native Linux editor and it won't give you hints about the syntax of the python code, although there are ways around that.
Yes, all good advice and I have experimented quite a bit but as I don't code much for the Pi (Python? Pah!) I've not had an issue to date. When I start coding C/C+ for the Pi that might change, of course.
@@RalphBacon
Cool :-)
Why multiply the reading by 1023 (2**10 - 1) in the one case, but 4096 (2**12) in the other? That's inconsistent...
Is one of them 10-bit and the other 12-bit? On the other hand, consistency has never been my strong point, Roy!
Shouldn’t it be 4095? Also he didn’t change the import library to the MCP3208 chip from the MCP3008.
Hi , I am using pi 4, is there a newer version for this analogue board, also the python is thorny python ide, is this the same
I believe this should work just the same, as long as they still expost the RUN pad.
Good video, but it would be nice to actually verify that you are getting 12 bits resolution by measuring Vin vs count out. Thanks!
Proof, you mean, Tab Maryland? 😳 From those fly-by-night MicroChip engineers? Gasp. Well, if I use this module again in a video I will try and remember to include this measurement!
The reason IC pins are not straight is for the pick and place machines. Pins will never be equally straight. By being all bent out, the pick and place tool holds the IC so pins are pushed in and this way they are all straight when inserted in the PCB
Well, there had to be a reason and this sounds as plausible as any, Kenneth, so it probably true. Those pick and place machines have a lot to answer for! Thanks for letting us know this.
Anyone have the library for the ADC ADS8345
Are you sure you have that part number correct, Vivin?
@@RalphBacon I'm sorry Ralph. It was a typo on my part. The part type was ADS 8345
I can't find a library for the Arduino (or any other µController) for this device, sorry.
After swapping to the 12-bit MCP3208 chip you need to update the Python code to use the proper device:
gpiozero.readthedocs.io/en/stable/api_spi.html#analog-to-digital-converters-adc
class gpiozero.MCP3008(channel=0, differential=False, max_voltage=3.3, **spi_args)[source]
The MCP3008 is a 10-bit analog to digital converter with 8 channels (0-7).
class gpiozero.MCP3208(channel=0, differential=False, max_voltage=3.3, **spi_args)[source]
The MCP3208 is a 12-bit analog to digital converter with 8 channels (0-7).
At 20:35 in the video that's why your max values bounce between 4092 and 4096, not single bits of noise.
I did try the other library before I did the video, but found no difference in behaviour. At that point, I thought that perhaps the libraries were identical but named differently just to match the chip. Perhaps I didn't do it right. I'll have another go and if I have more success I'll update in a future video. Thanks for the nudge, bubbasnmp.
Good luck! Shipping to USA is reasonable so might have to add this to my project list. Thanks for the video.
Normal people: Nord-VPN
Bacon: 0-VPN
I wish I knew what that means.
More for your ATtiny. Just need more memory.
My thoughts are, vonries, that the ATTiny and the Pi have nothing in common, apart from the fact they are both digital processors of sorts. If the Tiny can do the job we need look no further. And, sure, the Tiny can read three Analog inputs without recourse to another board, but it wasn't the point I was making in this video (which I'm sure you realise).
As you know I've done a few videos on the Tiny85, and it's amazing what it can do given its size and price. But the RasPi is a different beast altogether. Now _there's_ an idea for another video!
Thanks for sharing
Nice project :-)
Thanks for your post, Asger Vestbjerg, good to hear from you.