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 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

import sensor, image, time, pyb

adc = pyb.ADC("P6")		# create an analog object from a pin
    val =   
    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

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:

The fix may be in the firmware.

Thanks for that. Unfortunately no change with that firmware.

The 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.

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. (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".

    # The ADC has 12-bits of resolution for 4096 values.
    print("ADC = %fv" % (( * 3.3) / 4095))

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.