Hi Pete!
Thanks for the tips, I have tried including the SwSerial bit and upon further research, I stumbled onto https://community.blynk.cc/t/blynk-serial-communication/19091 and https://community.blynk.cc/t/issues-using-usb-link-dsr-is-off-project-is-offline/17320/3. I realised that by using SwSerial, it causes my project to go offline on my phone app. Hence, I modified my code to use DebugSerial instead.
I managed to get the terminal up, it prints my test line of ‘nyoom’ however it does not print values from the phone’s gravity sensor, neither does it print at the timer intervals… Am still confused on how to read values from the phone sensor!
For now, I am testing the readings from the sensor by using the terminal print in the app. But eventually I will attempt to get the readings to print in the serial monitor of the arduino please advise if this is possible using Blynk?
Here is my updated code and thanks in advance!
#define BLYNK_PRINT DebugSerial
//#define BLYNK_PRINT Serial //uses software serial
//SoftwareSerial SwSerial(10, 11); // RX, TX (transmit and receive respectively)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); //Arduino uno board has one serial port at D0(RX) and D1(TX)
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = " ";
WidgetTerminal terminal (V1);
BlynkTimer timer;
int x;
int y;
int z;
BLYNK_WRITE(V0) {
int x = param[0].asFloat(); //force of gravity applied to axis x
int y = param[1].asFloat(); //force of gravity applied to axis y
int z = param[2].asFloat(); //force of gravity applied to axis z
}
BLYNK_WRITE(V1) {
{
terminal.println(param[0].asFloat()); //x
terminal.println(param[1].asFloat()); //y
terminal.println(param[2].asFloat()); //z
}
terminal.flush(); //ensure everything is sent
}
void setup()
{
// Debug console
//SwSerial.begin(9600); uses software serial
Serial.begin(9600);
Blynk.begin(Serial, auth);
terminal.clear(); //clear terminal content
terminal.println(F("nyoom")); //test line - check if terminal is up and working
terminal.flush(); //ensure everything is sent
timer.setInterval(1000L, x); //function "BLYNK_WRITE(V1) for x" runs every 1000ms = 1s)
}
void loop()
{
Blynk.run();
timer.run();
}
-Shin