Hi Sara and Rui,
Any help appreciated…
Error File “<stdin>”, line 13, there is no such line content, I suspect the ref is to: from board
——— Source ————–
import adafruit_sht31d
from board
i2c = board.I2C()
sensor = adafruit_sht31d.SHT31D(i2c)
print(sensor.temperature)
print(sensor.relative_humidity)
——— End Source ————–
I have code running OK on Thonny/Raspberry Pi 4b, but need it in VSC on an ESP8266 running MicroPython
Thanks,
G
Hi.
If you want to import a specific method, you need to: from module import method
If you want to import a complete module, you use: import module
You can’t have
from board
What do you want to import?
Regards,
Sara
Hi Sara
I am confused.
Surly the ‘board’ ref should somehow reference esp8266?
Thanks
G
Hi Sare,
I can get “board” to work just fine on a Raspberry Pi 4, but so far no success withe the ESP8266.
This if the code that works of the pi
import board
… import busio
… import adafruit_sht31d
… i2c = busio.I2C(board.SCL, board.SDA)
… sensor = adafruit_sht31d.SHT31D(i2c)
>>> print(‘Humidity: {0}%’.format(sensor.relative_humidity))
… print(‘Temperature: {0}C’.format(sensor.temperature))
Humidity: 36.87342641336691%
Temperature: 24.02800030518044C
Error message I get:
/Users/VNC/PycharmProjects/SHT35_ESP8266_001/venv/bin/python “/Users/VNC/Library/Application Support/JetBrains/PyCharmCE2021.3/plugins/intellij-micropython/scripts/microupload.py” -C /Users/VNC/PycharmProjects/SHT35_ESP8266_001 -v /dev/cu.SLAB_USBtoUART /Users/VNC/PycharmProjects/SHT35_ESP8266_001/main.py
Connecting to /dev/cu.SLAB_USBtoUART
Uploading files: 0% (0/1)
/Users/VNC/PycharmProjects/SHT35_ESP8266_001/main.py -> main.py
Traceback (most recent call last):
File “/Users/VNC/Library/Application Support/JetBrains/PyCharmCE2021.3/plugins/intellij-micropython/scripts/microupload.py”, line 139, in <module>
Still getting File “main.py”, line 2, in <module>
ImportError: no module named ‘board’
I don’t get that error with same code on the Pi 4……?
Hi,
In the Pi, you’re using circuitPython. The board module is exclusive to circuitpython.
Circuitpython is different than micropython. Each has its specific modules. The board module is not available in micropython.
I hope this is not confusing.
Regards,
Sara
Thanks,
I am now trying machine, witch I believe is correct, but still no success….
This appears to be correct, but just hangs:
from machine import Pin, I2C
# construct an I2C bus
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
i2c.readfrom(0x44, 4) # read 4 bytes from peripheral device with address 0x44
i2c.writeto(0x44, '12') # write '12' to peripheral device with address 0x44
buf = bytearray(10) # create a buffer with 10 bytes
i2c.writeto(0x44, buf) # write the given buffer to the peripheral
Hi.
What happens exactly?
Take a look at the documentation and check if you’re using the methods properly.
Here’s the link: https://docs.micropython.org/en/latest/library/machine.I2C.html?highlight=i2c#machine.I2C
Regards,
Sara