Multiple serial data from arduino to graph

One, I included this

Then edited the pretext to make it print on serial monitor. Open the serial Monitor on Arduino IDE, to view the updated data. Will help you troubleshoot as well.

data count is zero nothing is being pushed and serial monitor doesn’t show any data.
i added Serial.println(x_value ); to check if any data is being measured, and I was getting the value of x.

  1. Did you check your serial connections?
    TX -> RX, RX-> TX, GND to GND

  2. Have you put the bolt credentials? API key and Device ID in Arduino IDE?

  3. Use below print line only to troubleshoot, but make sure to turn off the serial, when pushing data to cloud.

  1. Currently, line graph can only plot to variables, you can use table graph to plot more than 2 variables.

Below, you can see the data being pushed to the cloud, like it is supposed to. Comment out Serial.print statements to avoid disturbance in the serial communication. You can use your lcd to view the data for updates.

i have checked the connections they are connected properly the output is getting generated in serial monitor not in cloud.

Can you send a snap of your Arduino script?

Till then, you can make a new file and use this script - https://gist.github.com/hippyaki/12be46e5cca4cc3a78e6b938145ebb6a

Make sure,

  1. Your 8 and 9 pin of Arduino is connected to Bolt. And 0 and 1 pin of Arduino is open. You should be able to see the serial monitor as well as pushing to the cloud.
  2. Your BoltDeviceCredentials.h file has the Bolt credentials (API key and Device ID) in it.
#include <BoltDeviceCredentials.h>
#include <BoltIoT-Arduino-Helper.h>

#include<LiquidCrystal.h> // lcd Header
#include <SoftwareSerial.h>  

SoftwareSerial mySerial(8,9);
LiquidCrystal lcd(7,6,5,4,3,2); // pins for LCD Connection
 
#define buzzer 12 // buzzer pin
#define led 13 //led pin
 
#define x A0 // x_out pin of Accelerometer
#define y A1 // y_out pin of Accelerometer
#define z A2 // z_out pin of Accelerometer

#ifndef API_KEY
#define API_KEY "xxxx"
#endif
#ifndef DEVICE_ID
#define DEVICE_ID "BOLT294433"
#endif

/*variables*/
int xsample=0;
int ysample=0;
int zsample=0;
long start;
int buz=0;
 
/*Macros*/
#define samples 50
#define maxVal 20 // max change limit
#define minVal -20 // min change limit
#define buzTime 5000 // buzzer on time
 
void setup()
{
lcd.begin(16,2); //initializing lcd

//Serial.begin(9600); 
mySerial.begin(9600); // initializing serial

boltiot.begin(Serial); 

delay(1000);
lcd.print("EarthQuake ");
lcd.setCursor(0,1);
lcd.print("Detector ");

delay(2000);

lcd.clear();
lcd.print("Calibrating.....");
lcd.setCursor(0,1);
lcd.print("Please wait...");

pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
buz=0;
digitalWrite(buzzer, buz);
digitalWrite(led, buz);

for(int i=0;i<samples;i++) // taking samples for calibration
{
xsample+=analogRead(x);
ysample+=analogRead(y);
zsample+=analogRead(z);
}
 
xsample/=samples; // taking avg for x
ysample/=samples; // taking avg for y
zsample/=samples; // taking avg for z
 
delay(3000);
lcd.clear();
lcd.print("Calibrated");

delay(1000);
lcd.clear();
lcd.print("Device Ready");

delay(1000);

lcd.clear();
lcd.print(" X Y Z ");
}

String data;
void loop()
{
 
int value1=analogRead(x); // reading x out
int value2=analogRead(y); //reading y out
int value3=analogRead(z); //reading z out
 
int x_value =xsample-value1; // finding change in x
int y_value=ysample-value2; // finding change in y
int z_value=zsample-value3; // finding change in z
 
/*displying change in x,y and z axis values over lcd*/
lcd.setCursor(0,1);
lcd.print(x_value );
lcd.setCursor(6,1);
lcd.print(y_value);
lcd.setCursor(12,1);
lcd.print(z_value);
delay(100);
 
/* comparing change with predefined limits*/
if(x_value  < minVal || x_value  > maxVal || y_value < minVal || y_value > maxVal || z_value < minVal || z_value > maxVal)
{
if(buz == 0)
start=millis(); // timer start
buz=1; // buzzer / led flag activated
}
 
else if(buz == 1) // buzzer flag activated then alerting earthquake
{
lcd.setCursor(0,0);
lcd.print("Earthquake Alert ");
if(millis()>= start+buzTime)
buz=0;
}
 
else
{
lcd.clear();
lcd.print(" X Y Z ");
}
 
digitalWrite(buzzer, buz); // buzzer on and off command
digitalWrite(led, buz); // led on and off command

/*Open Serial monitor to view the values */
Serial.print("x=");
Serial.println(x_value );
mySerial.println(x_value );
Serial.print("y=");
Serial.println(y_value);
mySerial.println(y_value );
Serial.print("z=");
Serial.println(z_value);
mySerial.println(z_value );
Serial.println(" $");
boltiot.processPushDataCommand(x_value, y_value, z_value);

}
  1. DEVICE ID are usally 7 digits, you are missing 1 digit probably.
  2. Remove Serial.print and myserial.print because that is interferring with the data being pushed to the cloud.

Once, you do the changes and it works, we will talk about why I asked you to remove them.

You can add below script in the program as well. But if you add #include <BoltDeviceCredentials.h> which is supposed to have the credentials in it already, then don’t call below script.

its showing only 6 digits for me, i tried both commenting mySerial and without commenting mySerial it didn’t work

just got output im only getting 2 values x and y in table form

1 Like

Oh you’re an old user then.

setChartLibrary('google-chart');
setChartTitle('earthquake');
setAxisName('time_stamp','value');
plotChart('time_stamp','x_value','y_value','z_value');

That must be an issue on our side! I will update you by tomorrow EOD with this.

Till then, you can remove time_stamp and directly use

plotChart('xvar', 'yvar', 'zvar');

Or use multiple line graph

var Graph1 = new boltGraph();
Graph1.setChartType("lineGraph");
Graph1.setAxisName('X-Axis Name','Y-axis Name');
Graph1.plotChart('time_stamp','xvar');
var Graph2 = new boltGraph();
Graph2.setChartType("lineGraph");
Graph2.setAxisName('X-Axis Name','Y-axis Name');
Graph2.plotChart('time_stamp','yvar');
var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('X-Axis Name','Y-axis Name');
Graph3.plotChart('time_stamp','zvar');
1 Like

Which script are you using? From the gist or have you commented the serial.print statements?

thankyou its working

1 Like

Can you asnwer this as well? So that other students who face trouble can solve as well.

im using the script you sent in github

1 Like

Can you post the serial monitor screenshot as well? It’d make things clearer, like how you can use software serial and not worry about what’s visible on the serial monitor.

2 Likes