2

I am trying to use pressure sensors and a LOLIN D32 pro microcontroller to measure water level. The two pressure sensors are MS5803 and BME280 below is my code

'''

import machine        
from machine import Pin, I2C        
import bme280, ms5803        
import time        

i2c= I2C(scl=Pin(22), sda=Pin(21), freq=10000)        
bme1 = bme280.BME280(i2c=i2c, address = 119)        
BuiltinLED = machine.Pin(5, Pin.OUT)         
BuiltinLED.value(1)         
WaterLevelDifference=0        

def depth():       
    [T1,P1,H1] = bme1.raw_values      #T in degrees C, P in hPa        
    [P2,T2] = ms5803.read(i2c=i2c, address = 118)        
    WaterLevelDifference = ((P2-P1)*100/9810)                
    return WaterLevelDifference         
depth()        
while WaterLevelDifference<100:        
    if WaterLevelDifference > 0.1:       
        BuiltinLED.value(0) #turns LED on        
    else:        
        depth()          
        time.sleep(0.5)        
        print(WaterLevelDifference)

'''

I have done i2c.scan() and it shows [118,119] but sometimes intermittently. What does this error mean?

bam2619
  • 21
  • 2
  • 1
    Which line of your code gives the error? Does it always give the error, or does it work intermittently? – nekomatic Feb 21 '20 at 12:44
  • i2c.scan() shows [118,119] but **sometimes intermittently** seems to indicate you have a flaky connection in your circuit – Jos Verlinde Oct 11 '20 at 15:44

0 Answers0