Today I connected my USB host board (see "hardware" section below) to my Wemos 1D device. It receives data from an outdoor "weather station receiver" and prints in to serial console in Arduino IDE.
- "ELV Wetterdaten Empfänger" (https://www.elv.at/usb-wetterdaten-empfaenger-usb-wde1-komplettbausatz-1.html)
- USB Host Mini (http://www.hobbytronics.co.uk/usb-host-mini) preinstalled with "Serial Driver for FTDI, CP210X, PL2303"
- Wemos 1D (https://www.wemos.cc/product/d1-mini-pro.html)
WEMOS 1D | USB HOST Board
5V +--> 5V
GND +--> 0V
D1 +--> RX
D2 +--> TX
#include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
SoftwareSerial swSer(D2, D1, false, 64); // D2 = TX; D1 = RX;
String inputString = ""; // string, for incoming data from swserial
boolean stringComplete = false; // is string completed?
void setup() {
Serial.begin(115200); // Serial com to PC
swSer.begin(9600); // Serial com to usbhost device
Serial.println("Startup!"); // Print startup message
}
void loop() {
serialEvent(); //Call serialEvent function to get data from serial device
if (stringComplete) {
if (inputString.startsWith("$")) { // print inputString only if it starts with $ as we dont need debug messages
Serial.print(inputString); // as the string contains a newline at the end we dont need a "println"
}
inputString = "";
stringComplete = false;
}
}
void serialEvent() {
while (swSer.available()>0) {
char inChar = (char)swSer.read(); // get data from swSer
inputString += inChar; // concatenate received data
if (inChar == '\n') { // if we receive a newline char the string is finished
stringComplete = true;
}
}
}
Startup!
$1;1;;;23,4;;;;;;;;51;;;;;;;12,0;46;0,0;9;0;0
$1;1;;;23,3;;;;;;;;51;;;;;;;12,0;46;0,0;9;0;0
$1;1;;;23,3;;;;;;;;51;;;;;;;11,9;46;0,0;9;0;0