Reading data via ADC from temperature sensor

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/code/ENV-TMP-Arduino-Sample-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/code/ENV-TMP-Arduino-Sample-Code.pdf


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.

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.

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?

Use the run bootloader feature to install this: https://github.com/openmv/openmv/blob/master/firmware/OPENMV4/firmware.bin

The fix may be in the firmware.

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?

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.

OK - much appreciated. I will wait until either of you have had the chance to do this.
Thanks!

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.
firmware.zip (966 KB)

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:

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

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.

Hi @otills , very interesting topic!
I similarly want to read temperature with the openMV H7+.
I was wondering whether you could post pictures of your setup. In particular: did you use the 3.3V out pin of the board to power the sensor? I was thinking of using these probes:
https://detail.tmall.com/item.htm?spm=a230r.1.14.16.3c1b3724iA4VQ4&id=43339849601&ns=1&abbucket=1&skuId=4568981571923

link doesn’t work.
you can use 3.3v from the board if you dont plan to draw more than 200 mA.
If so use extenal 3.3v but ensure that both gounds are connected together (from camera and external 3.3v)
I don’t prefer to use 3.3v from camera though.

I used these instructions, meant for Arduino:

I wired the sensor in “normal” mode to read the data from the DS18B20 thermal sensor and did the same as in the Arduino instructions, except that I used the ADC pin P6. Unfortunately when running the read_adc example script, the voltage does not change.
Since I was only able to use a 4.4 ohm resistor, not sure if this is the cause of the problem. I already ordered more resistors.

The sensor has a sink current of 4 mA. Why would you rather not use the 3.3V from the camera, @oramafanis ?

Dear friend this a digital sensor. Not switable for this input. P6 reads 0-3.3 volt and map the voltages to 0-4000 value.

Oh of course, you’re right… we’re reading bits and all… so I got confused by this thread’s title and progression. GPIO4 on that Arduino board seems to be an SDA port, so I would need a python package, etc.? I will dig further.

1 Like