Identify board from code?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Identify board from code?

Post by kwiley » Sun Apr 03, 2022 3:49 am

I see sys.platform, which returns "esp8266", which is certainly helpful, but is there a way to detect which of the various wrapper boards I'm running on? I want to configure the pins differently for different boards. For example, given an ESP-01's limitations, I want to reallocate the TX pin for other use, but on a D1 Mini (essentially an ESP-12), I want to use other pins for the same tasks.

Is this possible from code at run time? I've looked through the machine module a bit and don't see anything that does this.

Thanks.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Identify board from code?

Post by Roberthh » Sun Apr 03, 2022 6:07 am

That's not possible by the pure dtandard firmware. You can of course add a specific config file on the board which identifies the board type.

kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: Identify board from code?

Post by kwiley » Sun Apr 10, 2022 4:01 am

Thank you. Yeah, I know I can effectively set a constant to toggle the code between configurations. As you say, I could stash it in a file, but there's still the risk that the state file could get copied over with the wrong value due to various sporadic user errors. I was hoping for a definitive solution. I accept that it just isn't possible.

Thanks again.

Shards
Posts: 39
Joined: Fri Jun 25, 2021 5:14 pm
Location: Milton Keynes, UK

Re: Identify board from code?

Post by Shards » Sun Apr 10, 2022 7:12 am

Assuming you aren't running the same firmware on the ESP-01s and the D1s you could use the more limited set of modules on the 1M firmware to tell them apart.

Custom firmware with a suitable added module would work too but unless you already have the tool chain built that's a lot of work.

Post Reply