¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Has anyone successfully used the I2C bus from a u4b BASIC program? #u4b #Balloon


 

Hi All:

I'm trying to use a pressure sensor, the MEAS MS5607-02BA with a U4B board - presently in the middle of troubleshooting - right now I'm not seeing any of the contents for the internal ROM calibration coefficients. But - at the same time, I've yet to see that anyone has tried an external sensor connected by I2C to the U4B.

I understand that Hans is already using the I2C bus for the synth and temp sensors. What I am interested in knowing, is if anyone has been able to use I2C for an external sensor from the QDOS BASIC environment and its instruction set. It's very likely I'm making a mistake with my programming. But it would be reassuring to know that at least one person has been able to communicate with an external sensor (especially a pressure sensor) using the I2CW and I2CR commands.

For the MS5607 and at least one other pressure sensor I've looked at, there may be an additional issue in the U4B BASIC environment. The computation of pressure using the calibration data in the sensor ROM, includes some variables which might need to be signed 32 and 64 bit integer. Variables in the U4B environment are unsigned 32 bit.

Here's the code snippet I used to try to read one calibration register in the MS5607:

I2CW 238 0 30????????? (reset the sensor)
I2CW 238 0 160??????? (cmd to access the PROM contents)
LET Z = I2CR 239 0?? (lower 8 bits of cal constant #1)
LET Y = I2CR 239 1?? (upper 8 bits of cal constant #1)
LET A = 256 * Y + Z?? (calc C1 value into variable A)
PRINT "C1 = #VA"

Result was that Z=Y=A=0, which suggests that the read failed.

Steve NU7B

?


 

¿ªÔÆÌåÓý

Is it possible that this device was not calibrated (or is a cheap Chinese rip off) and doesn¡¯t have a calibration constant programmed into it? This kind of thing is not uncommon with DS18B20 encapsulated temperature sensors to the point where I have given up trying to find non-counterfeit encapsulated sensors. What do you get if you try to read the pressure data?

73, Willie N1JBJ

On Jan 29, 2023, at 3:56 AM, Steve R <nu7b@...> wrote:

?

Hi All:

I'm trying to use a pressure sensor, the MEAS MS5607-02BA with a U4B board - presently in the middle of troubleshooting - right now I'm not seeing any of the contents for the internal ROM calibration coefficients. But - at the same time, I've yet to see that anyone has tried an external sensor connected by I2C to the U4B.

I understand that Hans is already using the I2C bus for the synth and temp sensors. What I am interested in knowing, is if anyone has been able to use I2C for an external sensor from the QDOS BASIC environment and its instruction set. It's very likely I'm making a mistake with my programming. But it would be reassuring to know that at least one person has been able to communicate with an external sensor (especially a pressure sensor) using the I2CW and I2CR commands.

For the MS5607 and at least one other pressure sensor I've looked at, there may be an additional issue in the U4B BASIC environment. The computation of pressure using the calibration data in the sensor ROM, includes some variables which might need to be signed 32 and 64 bit integer. Variables in the U4B environment are unsigned 32 bit.

Here's the code snippet I used to try to read one calibration register in the MS5607:

I2CW 238 0 30????????? (reset the sensor)
I2CW 238 0 160??????? (cmd to access the PROM contents)
LET Z = I2CR 239 0?? (lower 8 bits of cal constant #1)
LET Y = I2CR 239 1?? (upper 8 bits of cal constant #1)
LET A = 256 * Y + Z?? (calc C1 value into variable A)
PRINT "C1 = #VA"

Result was that Z=Y=A=0, which suggests that the read failed.

Steve NU7B

?


 

Hi Willie,
So far, the Adafruit one from Digi-Key has been the best for me.?1528-1592-ND All the Amazon ones have been 5 to 7 degrees off.?
--
Colin - K6JTH?


 

Thanks, Colin, I guess you really do get what you pay for. I tried calibrating the offset on the Amazon ones, but then realized I needed (at least) gain and offset for each sensor, so I just threw in the towel and realized all I wanted to know was "too hot" or "too cold". Bu the Amazon ones aren't very reliable, so they just stop working, which is more of a pain than having spent $10 each on them in the first place. 8*)

Anyway, dunno if this helps the OP in any way...

73, Willie N1JBJ

On Jan 29, 2023, at 7:49 AM, Colin Kaminski <colinskaminski@...> wrote:

So far, the Adafruit one from Digi-Key has been the best for me. 1528-1592-ND All the Amazon ones have been 5 to 7 degrees off.


 

Hi Steve?
Here is a section of U4B basic that reads i2c on an external temp sensor? and the battery voltage under load that works fine

Dave VE3KCL

BAT
?
?OUT 7 1? ? ? ? ? ? ? ? ? ? ? ? ? /put 3.3v on output io 7 which has a load resistor
?LET M = 0
?FOR T = 1 TO 20
?LET M = M + BT? ? ? ? ? ?/average 20 battery readings
?NEXT
?LET M = M / 20
?PRINT "M", M? ? ? ? ? ? ?/ M is in millivolts
?OUT 7 0? ? ? ? ? ? ? ? ? ? ? /turn off i/o 7
?LET H = 0
?FOR T = 1 TO 3?
?LET G = I2CR 146 0? ? ? / read external temp sensor 3 times? ( note internal temp sensor is 144 and you ?
?IF G > 100? ? ? ? ? ? ? ? ? ? ?/ add 2 to 144 from? a base of 000 to 001 on the device number of the external sensor )
?LET G = G + 17? ? ? / adjust for kelvin
?ELSE
?IF G < 100
?LET G = G + 273? ? ? / adjust for kelvin
?ENDIF
?ENDIF
?DELAY 300? ? ?/ delay for readings?
?LET H = H + G
?NEXT
?LET G = H / 3? ? ? ?/ divide by 3
?PRINT G
?IF G > 299
?LET K = G - 300? ? /adjust for kelvin
?ELSE
?LET K = G - 200? ?/ adjust for kelvin
?ENDIF
?PRINT K
?


 

Hi Willie:

For the uncorrected pressure I'm also getting zeros, so this seems to be a communication issue. In looking over what Adafruit offers, I noticed that their module using the MPRLS sensor, has the correction applied internally, so that saves using math with variables that the U4B does not directly support (perhaps there is a programming workaround for signed 32 and 64 bit integer).

I'll order one of those sensors, but there's still some debug to do on the MS5607 - I'll take a look at the signal lines with a scope. This sensor is made in Switzerland and ordered from Mouser, so shouldn't be a source problem. I also may have uncovered a compiler bug which I'll write Hans separately about.

73,

Steve - NU7B


 

Thanks Dave - that's the reassurance that I needed. I still have some hardware debug to do, I'll post what I find.

73,
Steve - NU7B