• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

SHT31, 32 & 35 Temp & Hum- MicroPython ESP8266

Q&A Forum › Category: ESP8266 › SHT31, 32 & 35 Temp & Hum- MicroPython ESP8266
0 Vote Up Vote Down
Gary asked 3 years ago

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

Question Tags: sensor adafruit_sht31d Tempe & Hum - Visual Studio code MicroPython ESP8266
9 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

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
 

0 Vote Up Vote Down
Gary answered 3 years ago

Hi Sara
I am confused.
Surly the ‘board’ ref should somehow reference esp8266? 
Thanks
G

0 Vote Up Vote Down
Gary answered 3 years ago

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
 
 

0 Vote Up Vote Down
Gary answered 3 years ago

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>

0 Vote Up Vote Down
Gary answered 3 years ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

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

0 Vote Up Vote Down
Gary answered 3 years ago

Thanks,
I am now trying machine, witch I believe is correct, but still no success…. 

0 Vote Up Vote Down
Gary answered 3 years ago

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
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.