How to get Arduino/ESP32 device details in code? - arduino

I'm working on a project in which there is a server and several clients (ESP32). In short, It's client-server communication over WIFI. Right now, I'm using ESP32-wroom-32D. In future, for a client device, I might use some other Arduino device or other ESP32 module or a combination of both. For code simplicity, I shall be using the same code for both types of devices (Arduino/ ESP32) as they support a common Arduino platform. Therefore, I want to know if there is a way which I can get the device's information.
Eg.
Function: Get_device_details( ) or Get_device_id( ).
Output: "ESP32-Wroom-32D" or "Arduino Mega 2560"

The Arduino defines to identify a board are in form of ARDUINO_<board>, where <board> is the value from <x>.build.board from boards.txt for board <x>
For example for Arduino AVR boards, in the boards.txt file is uno.build.board=AVR_UNO so the define is ARDUINO_AVR_UNO.
And Arduino has 'architecture' identification define too. This has form of ARDUINO_ARCH_<arch.name>. The <arch.name> is the uppercase version of the folder name with the boards package version. For example AVR for packages/arduino/hardware/avr/1.6.21.

For esp boards, you can use the following arduino code to get chip ID,
#ifdef ESP8266
int chip_id = ESP.getChipId();
#elif defined(ESP32)
int chip_id = ESP.getEfuseMac();
#endif

Related

Is it possible to factory reset an arduino from hardware to remove bad user code?

I was troubleshooting why Serial1 was always throwing undefined errors in sketches I was trying to run when I found a solution posted online for a slightly different board that suggested this line:
HardwareSerial Serial1(2);
I uploaded it and now the Arduino doesn't show up in the IDE, did I remap it's serial communications? Why is this possible!
Is there any hardware factory reset option available on these boards? Did I just brick my device?
edit: It seems the STM32Cube programmer app can be used to communicate with the device but I'm not sure where to get the original firmware to flash. https://imgur.com/a/LbiHenf
Assuming from the tag in your question, I guess you have an STM32 – (BluePill) Development Board (STM32F103C8).
If you think that your board is not handling serial communication properly then you might consider burning bootloader to your board. This will reset the complete configuration of your board.
There are many ways in which you can burn bootloader to your board.
Using another Arduino board like Uno / Nano / Mega
Using an FTDI USB to TTL Serial Adapter.
You might want to go through tutorials list below:
Getting Started with STM32 using Arduino IDE: Blinking LED
Programming STM32F103C8 Board using USB Port

change Arduino I2C bus address continuously

an ADXL345 and IMU9252 are connected to an arduino pro mini through i2c bus. both modules have different addresses.
so i should change i2c address in slave(arduino) continuously to access both modules data.
I need to know how is it possible and if there is any standard solution to manage this situation?
P.S: I'm using RTimulib for mpu9252 and sparkfun for ADXL345.
so i should adopt the solution regarding to these libraries.
Assuming you are using the standard Arduino Wire library, you need to use beginTransmission to begin an I2C transaction:
Wire.beginTransmission(address)
Just put the correct device address as the argument to that function.

Arduino ESP8266 Library

I am new to arduino and just picked up myself an UNO and an ESP8266 module. I've managed to wire them all up properly and connected to my home network using the AT commands.
But now im trying to follow tutorials on the internet but the problem is every example includes a library
#include <ESP8266WiFi.h>
such as this example tutorial https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/example-sketch-ap-web-server
So I have tried googling for it but can't find anything. I'm assuming thats because its really simple and Im missing something quite obvious.
help?
If you wish to use the Arduino as the main part of your ESP8266 project, there are several ways to go.
Use the Arduino to issue AT commands to the ESP8266.
Create your own protocol or messaging system by programming up the
ESP8266 with (for example) nodemcu or the Arduino/ESP8266 project or
Espressif or others, then program up your Arduino with the same
protocol or messaging system so the two may talk.
Alternatively, just program your ESP8266 directly. No Arduino required. Doing so, you can turn the tables and get the ESP8266 to issue messages to the Arduino if for example if you wanted the many GPIO and sense pins of the Arduino to do something. If you only need a couple of extra GPIO pins, look at the ESP8266 range to get more GPIO pins, such as the ESP8266-12
Which to choose?
nodemcu will give you a good idea of the capabilities of the ESP8266
and may be a good starter, easy to flash, easy to program, but it is a poor finisher except for the most basic of programs.
espressif has a large toolchain, not pleasant to flash,
you'll be at the cutting edge, however the community support is
minimal
The Arduino/ESP8266 project is awesome, easy to flash, very fast,
very stable, and unlike nodemcu you can create a large project. As you noticed, any arduino project starting with #include <ESP8266WiFi.h> is not for the arduino, but for the ESP8266 using the arduino IDE https://github.com/esp8266/Arduino
The Sparkfun example, it's for the ESP8266 Thing and it's using the Arduino ESP8266 Core, to flash the module.
It's not Arduino code that communicates with the module over serial. You need to upload this code to ESP module and with the Arduino ESP8266 Core, it's possible to program the ESP directly from the Arduino IDE.

Use Arduino board as regular AVR microcontroller

I want to use ATmega2560 MC, but it manufactured only as surface mount IC which means i must make PCB to use it. I searched for a per-made kit and found Arduino Mega R3 board contains the desired MC. (It contains less I/O pins but that's OK for now). Can i implement my code (without any arduino code) in this board? or should i modify it to work with Arduino, also if it runs in the board will it be the same as normal IC or there will be differences in speed.
The MCU in the Arduino Mega2560 is a stock ATmega2560. There is no need to use the Arduino libraries to program it and no need to use the Arduino tools to communicate with it; avr-gcc and avrdude will work with it as normal. Note that you will need to select the appropriate programmer/protocol in avrdude for the bootloader programmed on the chip if you want to program it via serial rather than ISP.

Arduino Wifi Shield SPI commands

I'm currently using the Arduino Wifi Shield. It works fine with the Arduino Library, but I have a project in which I need to get rid of all the Arduino library, and use only the AVR-libc.
Therefore, in order to use the Wifi shield, I would like to know where there is a documentation about the protocol used on the SPI bus between the arduino and the shield, so that I do not need to use the Wifi Library.
Am I forced to look at the source code, or does any document exist?
Thanks.
The documentation for SPI will be contained in the datasheet for the MCU used in the Arduino. For AVR-based Arduinos, look in the section titled "SPI – Serial Peripheral Interface". For the Arduino Due, see the "Serial Peripheral Interface (SPI) Programmer Datasheet" section.

Resources