-
Notifications
You must be signed in to change notification settings - Fork 7
Initialization
First step to use the AllWize library is to instantiate and initialize a class object to use it. The library supports 3 different ways to create a new object:
- Providing a HardwareSerial object
- Providing a SoftwareSerial object (only available on some platforms)
- Providing RX and TX GPIOs (only available on some platforms)
Depending on the platform (architecture) and the specific board you are using some of the previous options will be available.
Using a HardwareSerial object is always preferred if possible since hardware UARTs are more reliable than software ones.
When using a HardwareSerial object to communicate with the radio module the library constructor expects a reference to that object and the GPIO for the radio reset pin (optional). Example:
Allwize allwize(&Serial, RESET_PIN);
Some boards have only one hardware UART and only one HardwareSerial object available and it uses to be connected to the USB debugging port. In this case, you might want to use a SoftwareSerial object to interface the radio module and use the HardwareSerial for debugging purposes.
To do it you will have to instantiate a SoftwareSerial object in you code and pass a reference to it to the library. Example:
SoftwareSerial SerialWize(RX_PIN, TX_PIN);
Allwize allwize(&SerialWize, RESET_PIN);
This is the recommended way to do it on an Arduino UNO (using the built-in SoftwareSerial library) or a ESP8266-based board (using plerup's ESPSoftwareSerial library), they both have the same API so the code is the same on both cases.
At the moment, this is useful when using an ESP32 platform since it takes cares of the peripherial configuration and serial object. It will also work for SoftwareSerial objects but the recommended way for these is the previous one. Example:
Allwize allwize(RX_PIN, TX_PIN, RESET_PIN);
- Using PlatformIO
- Using Arduino IDE