Reading data via ADC from temperature sensor

Discussion related to "under the hood" OpenMV topics.
otills
Posts: 16
Joined: Fri Aug 09, 2019 4:42 am

Reading data via ADC from temperature sensor

Postby otills » Fri Aug 09, 2019 5:52 am

Hi, I have been playing with the OpenMV for about six months and am really blown away by what this small low powered board can do. That said, my experience on the electronics side is more limited and I am stuck on what I suspect is a simple problem

I am attempting to get an OpenMV H7 to read data from an Atlas Scientific temperature sensor via P6 using ADC https://www.atlas-scientific.com/_files ... e-Code.pdf. The hookup is simple - three wires and after running issues I did try connecting the GND and V+ to an external power supply in case power over USB (as I am monitoring the output in the OpenMV IDE Serial Terminal) was causing the problems. I just get random fluctuating values. I am working from the logic in an Arduino script https://www.atlas-scientific.com/_files ... e-Code.pdf

Code: Select all

import sensor, image, time, pyb

adc = pyb.ADC("P6")		# create an analog object from a pin
while(True):
    time.sleep(5000)
    val = adc.read()   
    adc_point = 3.3/1024	# Value of one adc point - voltage/1024 (have also tried /4095)
    val *= adc_point		# Volts
    val *= 1000			# Convert to millivolts
    temp = 0.0512 * val - 20.5128		# Convert to temperature
    print(int(temp))
Any advice or guidance is appreciated.
User avatar
kwagyeman
Posts: 4436
Joined: Sun May 24, 2015 2:10 pm

Re: Reading data via ADC from temperature sensor

Postby kwagyeman » Fri Aug 09, 2019 9:33 am

Hi, the ADC may be broken in the latest firmware available. I think Ibrahim put a fix in for this but we haven't released anything in a while. Um, if you can build the firmware you can get the fix now. Otherwise I have to get home to make that fix.
Nyamekye,
otills
Posts: 16
Joined: Fri Aug 09, 2019 4:42 am

Re: Reading data via ADC from temperature sensor

Postby otills » Fri Aug 09, 2019 10:21 am

Hi, I don't know how to rebuild the firmware but could muddle through if pointed in the right direction. I have access to a Linux machine.
I just tried on an up until now still packaged H7 board running the 3.2.0 firmware and get the same issue - was the issue introduced prior to this release?

There seems to be no response whatsoever to the sensor - if I unplug it from ADC port 6 I still get the same readout within the same range. I have tried a second sensor in case the issue lies there, but this behaves the same. Any ideas?
User avatar
kwagyeman
Posts: 4436
Joined: Sun May 24, 2015 2:10 pm

Re: Reading data via ADC from temperature sensor

Postby kwagyeman » Fri Aug 09, 2019 10:47 am

Use the run bootloader feature to install this: https://github.com/openmv/openmv/blob/m ... rmware.bin

The fix may be in the firmware.
Nyamekye,
otills
Posts: 16
Joined: Fri Aug 09, 2019 4:42 am

Re: Reading data via ADC from temperature sensor

Postby otills » Fri Aug 09, 2019 11:18 am

Thanks for that. Unfortunately no change with that firmware.

The adc.read() output is the same regardless of whether anything is connected. Am I right in thinking that it should be working if powered over usb (I have tried with and without). I have also used a multimeter to confirm that the sensor is not defunct and is responding to temperature.

Are there any other options to get this sensor working with the OpenMV via something other than ADC?
User avatar
kwagyeman
Posts: 4436
Joined: Sun May 24, 2015 2:10 pm

Re: Reading data via ADC from temperature sensor

Postby kwagyeman » Fri Aug 09, 2019 11:25 am

No, it's just the method is broken in the H7 firmware. If you see our GitHub history we put a fix in for this so it must not be in the built firmware yet.

Maybe Ibrahim can build the firmware for you. I am on a trip but have my laptop with me. I can build it and post tonight.
Nyamekye,
otills
Posts: 16
Joined: Fri Aug 09, 2019 4:42 am

Re: Reading data via ADC from temperature sensor

Postby otills » Fri Aug 09, 2019 12:24 pm

OK - much appreciated. I will wait until either of you have had the chance to do this.
Thanks!
User avatar
kwagyeman
Posts: 4436
Joined: Sun May 24, 2015 2:10 pm

Re: Reading data via ADC from temperature sensor

Postby kwagyeman » Sat Aug 10, 2019 9:55 am

Hmmm, I remember the ADC for the H7 being fixed but maybe it's just broken right now and there's a github issue on it. Ibrahim is looking into this. The latest firmware is attached.

Question, can you power the sensor for the 3.3v pin from the OpenMV Cam? I remember the ADC being fixed before.
Attachments
firmware.zip
(966.21 KiB) Downloaded 151 times
Nyamekye,
User avatar
iabdalkader
Posts: 1214
Joined: Sun May 24, 2015 3:53 pm

Re: Reading data via ADC from temperature sensor

Postby iabdalkader » Sat Aug 10, 2019 12:40 pm

Hi, I just tested ADC and it seems to be working fine. There's a simple way to test ADC, just connect a wire between ADC (P6) and 3.3v out or GND. And run this script:

Code: Select all

import time
from pyb import ADC

adc = ADC("P6") # Must always be "P6".

while(True):
    # The ADC has 12-bits of resolution for 4096 values.
    print("ADC = %fv" % ((adc.read() * 3.3) / 4095))
    time.sleep(100)
It should print ~3.3v or ~0v
otills
Posts: 16
Joined: Fri Aug 09, 2019 4:42 am

Re: Reading data via ADC from temperature sensor

Postby otills » Mon Aug 12, 2019 4:02 am

Hi, thank you both for your help with this and apologies as It turns out that this was being caused by two non-OpenMV issues.

1) A mistake had been introduced in the line initialising the ADC -"P6" had been replaced with 6.
2) The sensor I was given is not an Atlas Scientific ENV-TEMP using ADC, but actually a OneWire DS18B20. I now have this sensor working as expected.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests