strange boot behavior esp8266+ max31856 -How to fix it?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
jf_vt
Posts: 9
Joined: Thu Nov 25, 2021 5:15 pm

strange boot behavior esp8266+ max31856 -How to fix it?

Post by jf_vt » Wed Dec 08, 2021 9:16 am

EDIT: Problem SOLVED
Hi
I have a very bizzard problem ( for me at least so if somebody could explain whats going on and how to fix it it will be great!

I have the following setup copied from this tutorial:
https://learn.adafruit.com/adafruit-max ... cuitpython

I use different nodemcu v2 or v3 and get the same behavior such as described below
I use stock adafruit max31856 boards
My boot and main are shown below (also taken from the internet with the necessary library so my personal coding is absolutely minimal).

Now here is the problem:
1-With all hardware connected as in the tutorial, the system dont start. Both repl and webrepl are not responding and the board does not respond to ping. So I cannot reproduce the tutorial result
BUT
2- If I disconnect the max31856 board and power the esp3266 Then wifi connection is established and webrepl is active and display negative temperatures as the max31856 is not connected
while webrepl is running I then connect the max31856board the webrepl remains live and temeprature shift from negative to 0C

3 if I then do ctrlC for keyboard interrupt I get a prompt
then I do on the prompt a soft reset:

Code: Select all

from machine import reset
reset()
and then I relaunch webrepl.
it works and I get the max31856 correct temperature.

So both my hardware and codes are (kind of..) correct but they dont start properly as it requires the complicated gimick described above to get temperature readings
The problem occur at boot time because if I remove main I cannot boot with max31856 board connected
so I am at a loss to figures out what's going on and how to fix it.... ( maybe some specific boot instructions that I am not aware of...)
Any help will be welcome
Thanks
boot.py:

Code: Select all

import uos, machine
import time
import machine
import micropython
import network
import esp
esp.osdebug(None)
import gc
import ConnectWIFI
statusConnection=ConnectWIFI.connect()
print(statusConnection)
import webrepl
webrepl.start()
gc.collect()
main.py:

Code: Select all

import machine
from time import sleep_ms
import max31856
from max31856 import MAX31856
spi = machine.SPI(1, baudrate=5000000, polarity=0, phase=1)
cs = machine.Pin(15, machine.Pin.OUT)
cs.on()

therm = MAX31856(spi, cs,tc_type=max31856.MAX31856_K_TYPE)

while True:
    print('Temp: {} C (Junction: {} C)\n'.format(therm.read_temp_c(),therm.read_internal_temp_c()))
    sleep_ms(1000)
Last edited by jf_vt on Thu Dec 09, 2021 7:51 am, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: strange boot behavior esp8266+ max31856 -How to fix it?

Post by pythoncoder » Wed Dec 08, 2021 9:41 am

I suspect a power supply problem. The ESP8266 draws significant current when initialising the WiFi and, if the source can't provide it or the USB lead has too high a resistance, the voltage can drop. Try a different USB port and use a short USB lead. Another thing you might try is a delay before you initialise the device:

Code: Select all

cs.on()
sleep_ms(2000)  # Wait for supply to settle down
therm = MAX31856(spi, cs,tc_type=max31856.MAX31856_K_TYPE)
Peter Hinch
Index to my micropython libraries.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: strange boot behavior esp8266+ max31856 -How to fix it?

Post by davef » Wed Dec 08, 2021 9:42 am

Just a guess on my part:
https://www.instructables.com/ESP8266-U ... as-inputs/
specifically pin15 usage.

jf_vt
Posts: 9
Joined: Thu Nov 25, 2021 5:15 pm

Re: strange boot behavior esp8266+ max31856 -How to fix it?

Post by jf_vt » Wed Dec 08, 2021 10:35 am

@pythoncoder
Thanks but I dont think so
I use a 10W 5vpower supply when I dont need the repl and the problem is the same.
timer don't work and in fact I have the same problem without even running main.

@davef
Thanks for the ( very educated) guess. I was ignorant of this. Pin 15 is my cs pin so it can be it.
I will check immediately and see if it is the problem.
Will post my finding

jf_vt
Posts: 9
Joined: Thu Nov 25, 2021 5:15 pm

Re: strange boot behavior esp8266+ max31856 -How to fix it?

Post by jf_vt » Wed Dec 08, 2021 11:10 am

SOLVED
Davef suggestion nailed the issue ( thanks again)
as explained in Davef's quoted link, pin15 on Nodemcu plays a special role during boot time.
It appears after testing that this role is incompatible at a hardware level with being cs pin for a spi bus.
Unfortunately I was trying to use it as such!
I moved my cs pin to pin 3 ( nearby) and it works as it should

Post Reply