Arduino boards - what I wish I'd known when starting

 Arduino boards are an alternative to raspberry pi boards, for projects that involve custom hardware IO. For example a simple thermistor attached to take temperatures.

For that kind of application a full blown computer like the standard raspberry pi range is obviously massive overkill.

Well frankly for the purpose of reading a thermistor so is Arduino. 

But they are cheap as chips. My starting point was 3x esp32 boards for £21.95 with inbuilt wifi and bluetooth. It's hard to argue at those prices. The boards are at that price clones, but that's the point really, it is an open hardware standard.

As such there are a great number of variants. Code written for builtin wifi won't be quite the same for a board where you have added a wifi shield.

So how do you program them? Remarkably the default language supported by the public IDE is C++ and as an important note, if you download this for windows, get the full version don't get what the Microsoft store offers you, it lacks even the USB drivers! I assume it is possible for people to make it work, but I didn't figure it out. Linux is much smoother.

But let's backtrack, the language is C++, there are large numbers of libraries, how does that work with a little board? The simple answer is that it couldn't. The compilers and libraries sit on your PC or in the cloud IDE service and create the executable that gets uploaded to the board.

Because there are a large number of boards, the IDE needs to know which board. Some times the right board won't be listed and you will need to  add your board under "file/preferences/settings/additional board urls" for example my esp32 boards need:

I haven't looked under the bonnet, but these definitions contain both the header files pertinent to the board, so for example most boards have a #define for BUILTIN_LED says which gpio pin is the onboard LED, or in the case of the esp32 there is no definition as the onboard LED isn't addressable.

The other thing the definitions address is exactly how to talk to the board to upload your executable. So if you have the wrong board it might compile, it may or may not upload and it may or may not work as expected!

The code is called sketches and the IDE gives access to a vast array of example code.

So the sequence is.

  1. Write your sketch on the IDE
  2. Hit the upload button/
  3. The code will compile on your PC or in the cloud using C++.
  4. If the comms tot the board are right, it will upload and run. The board will only run one the one dedicated sketch.
  5. You may see debug output in the serial monitor which needs to be set to the baud rate you have asked for in the sketch.

Since  all we are doing is uploading an executable file, it is possible to use a language of your choice and Python is used by some people.

So bullet points.

  • Avoid the Microsoft store!
  • Make sure you are set to the correct board in the IDE.
  • You are flashing the device with a program compiled elsewhere.



Popular posts from this blog

Goodbye Tuya it really hasn't been great knowing you.

A Trait worse than death