The AllWize K2 is a prototyping board with the same form factor as the MKR series by Arduino. It is based on a SAMD21G microcontroller by Atmel/Microchip which is much more powerful than the 8-bits microcontrollers like the ATMega328 in the Uno or Leonardo.
ATSAMD21G128A Features:
The radio module, as with the AllWize K1, is a Radiocrafts RC1701HP with the WIZE firmware loaded (version 1.0 as of today).
Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager.
https://raw.githubusercontent.com/AllWize/allwize-boards/master/package_allwize_boards_index.json
into the Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.PlatformIO compatibility is on the way (see https://github.com/platformio/platform-atmelsam/issues/71
).
In the meantime you have two options to use the AllWize K2 from PlatformIO:
You can modify your local copy of PlatformIO to include the required files. To do so, follow the next steps (here <version>
is the latest folder, 0.1.1
as of August 2019):
<version>/boards.txt
file to the Platformio framework-arduinosam
package folder as boards_allwize.txt
<version>/variants/allwizek2
folder to the Platformio framework-arduinosam
package variants
folderallwizek2.json
file to the Platformio atmelsam
platform boards
folderIf using Linux, you have a script in the repository that does all these steps for you, just call it from the repo root folder with the version you want to install:
$ ./pio-install.sh 0.1.1
You can also configure the connections to the radio module manually from your script and build the code for the MKRZERO board like this:
#include "wiring_private.h" // pinPeripheral() function
#define RX_PIN (29ul)
#define TX_PIN (26ul)
#define RESET_PIN (30ul)
Uart SerialWize(&sercom4, RX_PIN, TX_PIN, SERCOM_RX_PAD_3, UART_TX_PAD_0);
void SERCOM4_Handler() {
SerialWize.IrqHandler();
}
#define MODULE_SERIAL SerialWize
#define DEBUG_SERIAL SerialUSB
And then initialize de GPIOs in your setup code:
pinPeripheral(RX_PIN, PIO_SERCOM_ALT);
pinPeripheral(TX_PIN, PIO_SERCOM_ALT);
Once it is included by the PlatformIO team you will be able to setup the board like this:
pio init -b allwizek2
pio lib install AllWize
REMEMBER: This option is not yet supported!!
/*
AllWize - Simple Slave Example - AllWize K2
Simple slave that sends an auto-increment number every 5 seconds.
Copyright (C) 2018-2019 by AllWize <github@allwize.io>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AllWize.h"
#if not defined(ARDUINO_ALLWIZE_K2)
#error "This example is meant to run on an AllWize K2 board!"
#endif
// -----------------------------------------------------------------------------
// Configuration
// -----------------------------------------------------------------------------
#define WIZE_CHANNEL CHANNEL_04
#define WIZE_POWER POWER_20dBm
#define WIZE_DATARATE DATARATE_2400bps
#define WIZE_UID 0x20212223
// -----------------------------------------------------------------------------
// AllWize
// -----------------------------------------------------------------------------
AllWize * allwize;
void wizeSetup() {
SerialUSB.println("Initializing radio module");
// Create and init AllWize object
allwize = new AllWize(&SerialWize, PIN_WIZE_RESET);
allwize->begin();
if (!allwize->waitForReady()) {
SerialUSB.println("[WIZE] Error connecting to the module, check your wiring!");
while (true);
}
allwize->slave();
allwize->setChannel(WIZE_CHANNEL, true);
allwize->setPower(WIZE_POWER);
allwize->setDataRate(WIZE_DATARATE);
allwize->setUID(WIZE_UID);
//allwize->dump(SerialUSB);
SerialUSB.println("[WIZE] Ready...");
}
void wizeSend(const char * payload) {
char buffer[64];
snprintf(buffer, sizeof(buffer), "[WIZE] Sending '%s'\n", payload);
SerialUSB.print(buffer);
if (!allwize->send(payload)) {
SerialUSB.println("[WIZE] Error sending message");
}
}
// -----------------------------------------------------------------------------
// Main
// -----------------------------------------------------------------------------
void setup() {
// Init debug serial
SerialUSB.begin(115200);
while (!SerialUSB && millis() < 5000);
SerialUSB.println();
SerialUSB.println("[MAIN] Basic slave example");
// Init radio
wizeSetup();
}
void loop() {
// This static variables will hold the number as int and char string
static uint8_t count = 0;
static char payload[4];
// Convert the number to a string
itoa(count, payload, 10);
// Send the string as payload
wizeSend(payload);
// Increment the number (it will overflow at 255)
count++;
// Polling responses for 5 seconds
delay(5000);
}
/*
AllWize - Simple Master Example - AllWize K2
Listens to messages on the same channel and data rate
and prints them out via the serial monitor.
Copyright (C) 2018-2019 by AllWize <github@allwize.io>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AllWize.h"
#if not defined(ARDUINO_ALLWIZE_K2)
#error "This example is meant to run on an AllWize K2 board!"
#endif
// -----------------------------------------------------------------------------
// Configuration
// -----------------------------------------------------------------------------
#define WIZE_CHANNEL CHANNEL_04
#define WIZE_DATARATE DATARATE_2400bps
// -----------------------------------------------------------------------------
// Wize
// -----------------------------------------------------------------------------
AllWize * allwize;
void wizeSetup() {
// Create and init AllWize object
allwize = new AllWize(&SerialWize, PIN_WIZE_RESET);
allwize->begin();
if (!allwize->waitForReady()) {
SerialUSB.println("[WIZE] Error connecting to the module, check your wiring!");
while (true);
}
allwize->master();
allwize->setChannel(WIZE_CHANNEL, true);
allwize->setDataRate(WIZE_DATARATE);
char buffer[64];
snprintf(buffer, sizeof(buffer), "[WIZE] Listening... CH %d, DR %d\n", allwize->getChannel(), allwize->getDataRate());
SerialUSB.print(buffer);
}
void wizeDebugMessage(allwize_message_t message) {
// Code to pretty-print the message
char buffer[512];
if (CI_WIZE == message.ci) {
snprintf(
buffer, sizeof(buffer),
"[WIZE] C: 0x%02X, CI: 0x%02X, MAN: %s, ADDR: 0x%02X%02X%02X%02X, CONTROL: %d, OPID: %d, APPID: %d, COUNTER: %d, RSSI: %d, DATA: { ",
message.c, message.ci,
message.man,
message.address[0], message.address[1],
message.address[2], message.address[3],
message.wize_control, message.wize_operator_id, message.wize_application, message.wize_counter,
(int16_t) message.rssi / -2
);
} else {
snprintf(
buffer, sizeof(buffer),
"[WIZE] C: 0x%02X, CI: 0x%02X, MAN: %s, ADDR: 0x%02X%02X%02X%02X, RSSI: %d, DATA: { ",
message.c, message.ci,
message.man,
message.address[0], message.address[1],
message.address[2], message.address[3],
(int16_t) message.rssi / -2
);
}
SerialUSB.print(buffer);
for (uint8_t i=0; i<message.len; i++) {
char ch = message.data[i];
snprintf(buffer, sizeof(buffer), "0x%02X ", ch);
SerialUSB.print(buffer);
}
SerialUSB.print("}, STR: \"");
SerialUSB.print((char *) message.data);
SerialUSB.println("\"");
}
void wizeLoop() {
if (allwize->available()) {
// Get the message
allwize_message_t message = allwize->read();
// Show it to console
wizeDebugMessage(message);
}
}
// -----------------------------------------------------------------------------
// Main
// -----------------------------------------------------------------------------
void setup() {
// Setup debug serial
SerialUSB.begin(115200);
while (!SerialUSB && millis() < 5000);
SerialUSB.println();
SerialUSB.println("[MAIN] Wize Master Example");
SerialUSB.println();
// Init radio
wizeSetup();
}
void loop() {
// Listen to messages
wizeLoop();
}