Go Down

Topic: Storing incoming data from Arduino with Processing..having trouble (Read 615 times) previous topic - next topic


I am using an Arduino with a cellular module as a "modem" for my computer. I send it data via txt message.

The code successfully recognizes incoming characters and takes action, however I need it to store the text message "text" in an array that I can use. The code does everything correct except generate the array. I have included the code, I have a hunch that it's something to do with either where/how the storeData function is called OR the for loop I use to store data. Please take a look! Thanks so much

Code: [Select]

import processing.serial.*;
import processing.net.*;

//Serial Variables
Serial myPort;           // the serial port you're using
String portnum;          // name of the serial port
String inString = "";    // the string coming in from the serial port
int inByte;

//SMS Variables
int SMS_counter = 0;
String stat = "";
String GBstat = "";
char[] SMS_data = new char[10];

//HTTP Variables
Client client;
int sent_num = 0;
boolean requestInProgress = false;
String responseString = "";
String requestString = "";
String callStat= "";

void setup()
  size(600, 800);       
  PFont myFont = createFont(PFont.list()[2], 14);
  portnum = Serial.list()[1];
  myPort = new Serial(this, portnum, 9600);

void draw()
  text("SMS Counter:\n" + SMS_counter, 10,20);
  text("Status:\n" + GBstat, 10, 60);
  text("HTTP Call Status:\n" + callStat, 10,100);
  text("# HTTP Requests Sent:\n" + sent_num, 10,140);
  text("Data Received:\n" + SMS_data, 10,180);
  text("Received:\n" + inString, 10, 220);

void serialEvent(Serial myPort)
  int inByte = myPort.read();
  inString += char(inByte);

if(char(inByte) == '?')
  SMS_counter = 1;

if(SMS_counter == 1)
  SMS_counter = 0;

if(char(inByte) == 'g')
  stat = "Good";
  GBstat = "Good";

if(char(inByte) != 'g' && char(inByte) == 'b')
  stat = "Bad";
  GBstat = "Bad";


void makeHTTPCall()
  if (stat == "Good" || stat == "Bad")
    callStat = "Entered HTTP Loop";
    println("Entered HTTP Loop");
    callStat = "";
  if (requestInProgress == false)
    client = new Client(this, "www.example.com", 80);
    requestString = "example"; //+stat;
    client.write("GET " + requestString + " HTTP/1.0\n");
    client.write("HOST: example.com\n\n");
    requestInProgress = true;
    stat = "Null";
    callStat = "HTTP Request Sent";
    sent_num = sent_num + 1;
requestInProgress = false;

void storeData()
  if(char(inByte) == '?')
    for( int i=0; i<10; i = i+1)
     SMS_data[i] = char(inByte);


You are aware, I presume that draw() is called over and over, like loop() in an Arduino sketch. Unlike loop(), however there is a pause between executions, to maintain a constant frame rate. The default is to call draw 30 times per second. Sending requests 30 times per second seems a little too often.

I have a hunch that it's something to do with either where/how the storeData function is called OR the for loop I use to store data.

Where in that code do you think you actually store any data in any array?

Code: [Select]
if(char(inByte) != 'g' && char(inByte) == 'b')
If inByte is 'b', is there any way it could not not be g? If it is 'b', then clearly it is not 'g', so the first part of that test is silly.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131