question

nebulight avatar image
nebulight asked

Raspberry Pi Analog inputs (Tank input)

I'd like to reopen discussion on this topic. I'm a novice and freely admit that I really don't understand all aspects of how to get this to work. So I may be totally off with this so please correct me if I'm wrong. I've read this thread:

https://groups.google.com/forum/#!msg/victron-dev-venus/mejgJbMjU34/yogWAU5wCAAJ;context-place=forum/victron-dev-venus

I purchased the same board as what's here, the Expander Pi with the mcp3208 12-bit ADC.

From reading this, I'm a bit confused how to wire this up. In that thread, they point to the reference voltage of 1.8v. However the expander pi has a reference voltage of 4.096. But in other threads, they talk about a reference voltage of 5v. I also see the schematic of the BBB Cape and it says 5v as well:

I'm not sure what is correct or if the reference voltage even matters since both are 12-bit ADCs, the reference voltage shouldn't matter as it's just reading the resistance of the sender. But then I'm confused on how to wire this up with the Expander Pi. Anyone who has this board, would they care to share their setup, possibly with photos or diagrams? I'd appreciate it.

tagging @WKirby as you've always been super helpful!

Venus OSRaspberry Pitank monitor
tank.png (51.9 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

8 Answers
nebulight avatar image
nebulight answered ·

HOLY COW! I've gone from knowing pretty much nothing about this kind of stuff to getting it to actually work!! I was really thrown off the by the schematic above. You are feeding 5V to the tank sender, but the input to the ADC thanks to the resistors brings the voltage down so you actually need a voltage reference of 1.8v on the ADC top row second pin. I ordered an expander pi with a vref on board to 1.8v, but it was damaged in shipping. While I waited, my curiosity got the better of me, so I bought some wire, breadboards and a physical ADC chip and made this mess:


I took the 3.3v pin on the pi and made a voltage divider with two resistors (56kohm and 68kohm). The orange wire in the middle of the two resistors went to the ADC vref pin as that's around 1.8v (close enough for my testing, hopefully the vref chip will be more accurate). Then to get the signal wire to the ADC, I just copied the schematic above. I fed 5v to a 680 ohm resistor, then connected that to a 10kohm resistor, then a signal wire (in green) to the ADC port 5 (tank 1). I then hooked up the signal wire (red exiting to the left) to the tank sender. I loaded the ADC dbus driver from the post above and ran the commands. Rebooted the pi and my tank sender was showing 100%!!!! I lowered it to around half and was around 50-55%! Down to almost empty and it was at 4%! IT'S WORKING!!!!! The only thing that is odd (and I think it's a feature of the OS) is that when you lower the tank level, it's pretty quick. However when you fill the tank and raise the level, it SLOWLY increases. I think this is to prevent sloshing around (I think I read that on another post). So this will be a problem when I try to fill my aux diesel tank in my camper van, but that's something I can work around. I plan on making a full write up/video for youtube to help people like me who are clueless. Huge thanks to @Rob Duthie for his help with my beginner questions over email. And big thanks to Victron for making your software open source and all the users on the google group that did all the heavy lifting!


Your browser does not support HTML5 video.


16 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Ralf Klüber avatar image Ralf Klüber commented ·

Any configuration on the rPi? How does Venus OS know which GPIOS being used?

0 Likes 0 ·
nebulight avatar image nebulight Ralf Klüber commented ·

You need the ADC chip as you don't feed the information directly to the pi. It's easier to just buy a HAT but you can use this to wire up a raw MCP3208. Ignore the temp sensor and the vref voltage as that must be 1.8v. See the above post.

The venus software knows which ADC inputs it uses for each. Since this is based of the beaglebone board which is in the Venus GX, it's as followed:

ADC1: Not Used

ADC2: Not Used

ADC3: Tank 3

ADC4: Temperature 2

ADC5: Tank 1

ADC6: Temperature 1

ADC7: Tank 2

ADC8: No present on the beaglebone so not used

0 Likes 0 ·
1568061747768.png (589.3 KiB)
5teve avatar image 5teve nebulight commented ·

@nebulight - could you advise if anything would need to change to use the MCP3008 instead of the 3208 - the 3008 is a 10 bit chip.. and available locally to me.

Thanks

Steve

0 Likes 0 ·
hugyourewoks avatar image hugyourewoks commented ·

Hey @nebulight I'm pretty new to victron on raspberry pi. I've played around on pi before, but in a general way. I have a camper van and want to add two tank level sensors to my system and have Venus Os monitor them. You used a pi 3+ right? Which HAT do you recommend? The HAT takes the resistance measurement from the sensor and allows the OS to view correct? I could just buy a Venus GX, but I don't have any other victron components, so the plug and play functionality with my solar charge controller and inverter won't work. That's, okay, I just like the Venus OS look and ease of use with my onboard LTE router and VRM upload. Is the HAT option easier than the breadboard, or are they complimentary? I love learning about stuff like this so, I don't mind learning about all that.

This is the sensor I'm going to get.

KUS USA SSS Fuel & Water Level Sensor, 10" https://www.amazon.com/dp/B00Y831RM0/ref=cm_sw_r_cp_apa_i_F8.4Db846306H

0 Likes 0 ·
nebulight avatar image nebulight hugyourewoks commented ·

To answer your questions, yes I'm using a 3+. The problem with a HAT is most available don't have the correct vref so you'll have to modify it. You'll also need to add the correct resistors in order to make it work. I've been playing around with the expander pi unit because that has the correct ADC, but will all the modifications it would require, I'd recommend just buying the ADC chip, some blank PCB boards and solder everything yourself. The breadboard was just for testing, wasn't meant to be a permanent install.

With that said, if you don't have any other victron components I'm not sure it's a good use of your time to have a GX device only for tank monitoring. Blue sea is coming out with a compact tank monitor that looks pretty nice and is reasonably priced. https://www.bluesea.com/products/1739/Mini_OLED_Tank_Meter_-_Yellow They also have a 4 tank monitor, but it's more expensive than buying 4 of these.


0 Likes 0 ·
hugyourewoks avatar image hugyourewoks nebulight commented ·

@nebulight True, I don't have Victron components, but I'm thinking of adding a BMV 712 to monitor voltages and current via the MK3 USB. I think the remote monitoring is worth the trouble plus a Pi is cheap. Hardware side, I can just plug the ADC 3028 into the Pi pins and then the sensor into the right channel correct?

0 Likes 0 ·
nebulight avatar image nebulight hugyourewoks commented ·

If you are going to get a 713 then go for it for sure.

As for the adc, you could go that route but it would be cleaner with a pcb board. I’ve been meaning to solder mine up. I have some boards and bought a Phoenix connector. I already have the adc and resistors to do it. I’ll probably have time this weekend.

0 Likes 0 ·
nebulight avatar image nebulight hugyourewoks commented ·

It would still require modifications to work properly to get your vref to 1.8 and the required resistors to down the voltage before the input.

0 Likes 0 ·
nebulight avatar image nebulight hugyourewoks commented ·

Oh and the mk3 to usb is for a multi. You’d need a ve.direct to usb for the 712.

0 Likes 0 ·
Ralf Klüber avatar image Ralf Klüber nebulight commented ·

Hi, I have been there as well. Tried rPi plus head etc. finally decided to go for a GX. Stability is stellar. power supply is in there as well. No soldering, no tinker. No regrets. Do the math. You safe 100€ max with DYI and rPi.

0 Likes 0 ·
nebulight avatar image nebulight Ralf Klüber commented ·

Agreed. With the cerbo go right around the corner, if it’s priced right I may ditch my pi.

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie nebulight commented ·

Hi

Well my Raspi is working perfectly on temp and tank levels very stable,

just need the right design to make it work like a GX.

I have all the design in place for the PCB etc.

Just adding the relays to make up for 4 relay outputs etc.

Rob D

NZ

0 Likes 0 ·
nebulight avatar image nebulight Rob Duthie commented ·

Still waiting for your Venus Pi Hat @Rob Duthie ;)

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie nebulight commented ·

Hi

Once i have the relays sorted then i can finish the design layout to allow for the total of 4x relays.

Just having issues with the procedure to do that, if someone can provide the procedure to do this it would benefit all.

Adding in relays procedure

I have 2x relays all working OK to date. Matt has had four going which i have tested using his image file, but up dating to the test ver 2.40.43 stopped all that.

Note: i am funding this my self and it will be made available to all.

the only cost will be the completed PCB ready to plug and go with all terminals etc.

Update 14/12/2019 All 4x relays are active now, the main schematic is done, just a few mods for voltage clamping and PSU 10-55vdc module to add. then it is complete.

Regards

Rob NZ


0 Likes 0 ·
marco-lingua avatar image marco-lingua commented ·

"I loaded the ADC dbus driver from the post above and ran the commands"

Can you help me with this step? Which post above?

0 Likes 0 ·
bivaccamper avatar image
bivaccamper answered ·

Hi:

I would like to know if you made any progress on this. Thanks

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nebulight avatar image nebulight commented ·

I'm working on this still. I have ordered another Expander Pi but with a VREF of 1.8v installed however the unit was damaged in shipping so they are sending another one. Since it's coming from the UK (and I'm in the US) I just ordered a RAW MCP3208 ADC (that should be here Thursday) and with a breadboard and some resistors to get the vref from 3.3 to 1.8, I'm going to attempt to get it to work. I also purchased another fuel sender and raspberry pi (and touch screen) to keep on my workbench so I can test without going out to my van. @Rob Duthie has been SUPER helpful with answering my beginner questions. Hopefully I can get an answer in the next few weeks.

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie nebulight commented ·

Hi

I have being busy on another project. The supply volts needs to be 5v feed for your 3.3 to 1.8 vref,

I have tested the temp sensor side as well and all works OK using the BBBC wiring and values, Same applies to the tank levels.

One note: when using bread board the values will flick all over the place due to the small voltage values a 12 bit resolution, so need hard solder the temp circuit on vero PCB or some thing to get stable readings.


Regards

Rob D

NZ

0 Likes 0 ·
laurenceh avatar image laurenceh nebulight commented ·

I looked into this and documented my project here: https://community.victronenergy.com/idea/41865/home-brew-boxed-hat-and-cape-i2c-and-analogue-inpu.html

It was a simple one component modification to modify the Custard pi analogue interface to give it a 1.8v vref. The regulation of the 3.3v on the Rpi is so stable that a voltage divider (couple of resistors) is good enough. I have all 5 Temperature inputs, two read by Venus, and 3 read using my own driver, reporting the same temperature to within +/- 0.5 degrees of a couple of other calibrated temperature sensors.

0 Likes 0 ·
Ralf Klüber avatar image
Ralf Klüber answered ·

This is very helpful. Would you mind sharing the schematics you came finally up with? I volunteer to prettify it if required.

And what is your tank sensors resistance? I learned there are differences in EU and US.

17 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nebulight avatar image nebulight commented ·

I'm using an Expander Pi Raspberry Pi hat that has an ADC and has a vref of 1.8v. I'm going to make a separate board with manual solder PCBs with the schematic I posted on my first post. I'll feed the 5v from the Pi pins and have the same resistors and have a Phoenix connector for hooking up the actual senders. I'm new to all this, so I'll just post a photo when I'm done. It probably will be very crude but should work.

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie commented ·

Hi

Attached schematic.

Regards

Rob D

NZ

Victron Raspi Hat.pdf

0 Likes 0 ·
nebulight avatar image nebulight Rob Duthie commented ·

What’s the Eta?

0 Likes 0 ·
1579553734221.jpeg (118.3 KiB)
Rob Duthie avatar image Rob Duthie nebulight commented ·

Hi

I have a guy in the UK getting some PCB done now.

0 Likes 0 ·
nebulight avatar image nebulight Rob Duthie commented ·

Nice. Can you email me at nebulight (at) g m a il.co m when these are ready?

0 Likes 0 ·
nebulight avatar image nebulight commented ·

very very VERY crude but this is what I can up with. I'm not good at soldering but this is the board I came up with. The top white is 5V in and black is Ground. The Red and black in the middle is the tank input and the brown output will go to the ADC on the Expander Pi board (port 5 for Tank 1). I did have the VRef on the board replaced from the 4.096v to 1.8v. I had originally planned on doing the entire board for three tanks and two temp, but I will never use the other ports so I didn't bother.

Had the cerboGX been out when I built my pi, I would have just bought that. However I cut out some panels in my van to fit the 7 inch pi screen and the 5 inch Cerbo screen won't fit.


0 Likes 0 ·
1599686610061.png (1.5 MiB)
1599688748647.png (709.9 KiB)
jeroend avatar image jeroend nebulight commented ·

Perhaps a silly question: Why are you not simply changing the vref value to 4.096 in the dbus-adc.conf file?

0 Likes 0 ·
nebulight avatar image nebulight jeroend commented ·

I started this long ago before I even knew about the config file. All the old conversations never mentioned it and always talked about the vref as 1.8 so that’s why it was swapped out. I have another board that has the stock vref that I’ll try out.

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie jeroend commented ·

Tried that did not work very well, as there is in something else in the code that needs changing some were to correct it, just by using the 1.8v ref device solves all the issues and it works OK with no problems and is accurate.

Rob D

NZ

0 Likes 0 ·
trygvelu avatar image trygvelu jeroend commented ·

I have an ADC board with VRef tied to +5V. It works fine with just setting the Vref value in the dbus-adc config file. You just need the correct pull-up (680 ohm) to +5V. The 1.8V Vref will give better resolution on the adc values, but with tank sensors that's not really an issue.

0 Likes 0 ·
jeroend avatar image jeroend trygvelu commented ·

Thanks I will try that first then before making adjustments to the Vref.

0 Likes 0 ·
jeroend avatar image jeroend jeroend commented ·

I messed about quite a bit with the vref but also with the other components needed to make the tank sensors work. Like nebulight I omitted the BAT54S for the tank sensors and that works. (not sure what the BAT54S really improves, the 5V/3.3V on the pi seems stable enough)).

A different story is the temperature input. I just cannot get it to work (neither with 1.8V ref nor 4.096V) I connected it like in the schematic from Rob Duthie and can see a sensor value allright, it is just not displayed in the gui. There it says Reverse Polarity or Disconnected (or Unknown) when not connected at all. I tried a couple different LM335's but unless all 5 are broken or from a bad batch I need to do something else..... but what? Any suggestions?

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie jeroend commented ·

Have you updated the correct files and overlays into boot directory, for the MCP3208 chip set etc?

Regards

Rob D NZ

0 Likes 0 ·
jeroend avatar image jeroend Rob Duthie commented ·

Well I suppose so, since the tank inputs work it certainly looks that way. I can also see the value change and displayed if I read the dbus-adc.

I’ll try to downgrade the dbus-adc tomorrow to a lower version (currently on 1.27) to see if that makes a difference.

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie jeroend commented ·

I do have the copies the files i use with no issues at all for temp and tank readings. It can be slow to react due to having some hysteresis in the software to stop slosh readings.

I am running the latest version 2.60 to date.


Regards

Rob D

NZ

0 Likes 0 ·
jeroend avatar image jeroend Rob Duthie commented ·

It turned out all 5 LM335's I was using were broken or otherwise not fit to be used. I connected the temp sense cable that came with teh Victron Multiplus and that instantly gave a reading. Thanks all for trying to figure this one out. I will source LM335's from another place.

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie jeroend commented ·

The BAT54S are for static protection and over voltage protection.

0 Likes 0 ·
dennis-brok avatar image
dennis-brok answered ·

so its working ? ?


2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

ghostrider avatar image
ghostrider answered ·

Very cool to see this! I'm getting into a Pi setup now also and am considering the tank measuring tools. The catch for me is that I can't have resistive style senders. The sensors are already installed and wrapped in a outer tank that is insulated for winter use. Would be a HUGE headache just to install a new sensor.

So, I only have what is essentially 3 fluid sensors mounted at different heights in the tank - 1/3, 2/3, FULL..the level is determined by which of the 3 sensors/switches are triggered by fluid.

While it wouldn't be exact, since I only have a resolution of 4 sensors (empty or all off is the 4th option), I would like to try to get the sensors to read in Venus.

Any ideas on how the ADC could read this? While I did do some electrical engineering in college, but then lived a life of software so I've forgotten much. Cant remember how I would wire that. Maybe some form of series so that the voltage fed in matches what is expected as more switches are turned on?

4 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

wkirby avatar image wkirby ♦♦ commented ·

If you used a string of three 60Ω resistors in series to make up 180Ω. Then each of your three switches could connect across each resistor and short circuit that resistor when the level comes up o that switch. When all three switches are closed then the string will be 0Ω. Viola, 0-180Ω, although very coarse.
Now, 60Ω resistors are non existent, closest is 60.4Ω in the E96 range which are probably stupidly expensive. You can make up a 60Ω resistance by using two 30Ω resistors from the more common E24 range.

0 Likes 0 ·
Ian Jordan avatar image Ian Jordan commented ·

Sorry if this is a bit late, did you ever try this? We are in exactly the same position with our CBE level sensors so I want to do the same thing. I'm just trying to understand where this resistance network output is then hooked up to?

0 Likes 0 ·
jeroend avatar image jeroend Ian Jordan commented ·

To one of the ADC ports and Ground

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie jeroend commented ·

Hi Schematic of a working raspi HAT with all functions running.

Regarsd
Rob D

NZ

Victron Raspi Hat.pdf

0 Likes 0 ·
victron-raspi-hat.pdf (704.3 KiB)
5teve avatar image
5teve answered ·

@nebulight @Rob Duthie

HI Both - I have copied the work posted above (using the pictures of the breadboard and descriptions), but using a mcp 3008, I muddled my way though the software side.. i have checked double checked and triple checked the wiring on the breadboard, I have tanks and temp sensors appear, however I cannot get a reading that makes any sense

I am using a 240-30 waste gauge (reads correctly with the multimeter) however when I hook it up, empty is showing as 82% and full goes short circuit in the remote console.

Would using the 3008 make a difference with being 10 bit? Could anyone suggest where to look for troubleshooting this. I'm new to this kind of thing so fairly certain its probably me.. however i am failry good at copying stuff :)

Correct resistors are in place. I have a 1.8v ref voltage and vdd of about 4.7v

The 5v nominal feed to the gauge measures about 0.6v after the 680r resistor (hoping thats right!)

Any suggestions would be gratefully received as i want to use something like this (or maybe a modified hat) until The Stetson is available..


Steve

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Rob Duthie avatar image Rob Duthie commented ·

Hi

Analog input is setup for the MCP3208 chip which is 12 bit , you need proper Vref chip to get accurate readings, i have used the resistor network in testing and they are poor and depending on the input voltage it swings to much causes errors and bad readings.

Fit a Vref chip and all problems go away.

You have load the correct modified dtb file for the MCP3208 chip set into the Uboot overlays folder?

Victron Raspi Hat.pdf

Regards

Rob D

NZ

0 Likes 0 ·
victron-raspi-hat.pdf (704.3 KiB)
5teve avatar image 5teve Rob Duthie commented ·
@Rob Duthie Thanks...

I can only get the 3008 chip locally to me (im impatient)

I loaded the DTB file for the 3008 and get readings for the analogues in the remote console so assuming thats ok. The DTB file came from a search online..

With regard to accurate.. close would be ok.. but this is all over, the remote console obviously damps the readings.. but when it should be at 0% it sits on 82% so not even close.. if it was swinging around.. then yes i'd understand I need better.. but when its out by this much i'm figuring something else is wrong! Is set up the same as @nebulight shows in his images.. but not giving the same results..

I'm sure just getting a hat would be easier.. i've just gotta find one and then work out how to change the vref on it.. or just buy a cerbo.. haha

Steve

0 Likes 0 ·
Rob Duthie avatar image Rob Duthie 5teve commented ·

Hi

You need the correct dtb file as my file has being modified to suit the 12 bits etc.

The Vref is very important to have stable otherwise the readings are all over the place. I have done the same it was hopeless.

Regards

Rob D

NZ

0 Likes 0 ·
adamr100 avatar image
adamr100 answered ·

@nebulightDo you still have a source in the UK who I can purchase one of these boards off?

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nebulight avatar image nebulight commented ·

Expander Pi was the hat, but it will take some modification to get working right.

https://www.abelectronics.co.uk/p/50/expander-pi


0 Likes 0 ·
trygvelu avatar image
trygvelu answered ·

Just adding some information to this thread for anyone who might be struggling to get the mcp3208 or similar ADC up and running on their Raspberry Pi with newer versions of the Venus OS. The mcp3208 overlay file didn't work for me, atleast.

  1. Get anyspi overlay file from raspberry repo: wget https://github.com/raspberrypi/firmware/raw/master/boot/overlays/anyspi.dtbo and copy it into /u-boot/overlays/anyspi.dtbo
  2. Append this entry in /u-boot/config.txt: dtoverlay=anyspi:spi0-0,dev="microchip,mcp3208" (for mcp3208 connected to SPI with CS0)
  3. Backup original /etc/venus/dbus-adc.conf and replace with something like this (you may have different vref, and other sources..):
    device  iio:device0
    vref    5.0
    scale   4095
    label  "fuel"
    tank    4
    label  "freshwater"
    tank    6
    label  "spare tank"
    tank    2
    label  "temp 1"
    temp    5
    label  "temp 2"
    temp    3
  4. Reboot, verify that /sys/bus/iio/devices/iio\:device0/ exists, and dbus-adc is running
2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Rob Duthie avatar image Rob Duthie commented ·

Hi


Have you tested on the raspi 4 models?

On the raspi 3 it works fine. On the raspi4 the /sys/bus/iio/devices/iio\:device0/ is missing?

Below is the dbus-adc.conf that gives me 4x tanks and 4x temps.

i use a modfied mcp3208-overlay.dtb file to make it all work

device iio:device0

vref 1.8

scale 4095

tank 0

tank 1

tank 2

tank 3

temp 4

temp 5

temp 6

temp 7

0 Likes 0 ·
trygvelu avatar image trygvelu Rob Duthie commented ·
Have not tested with raspi 4, sorry..
0 Likes 0 ·