Go Down

Topic: String Detection/Manipulation question (Read 287 times) previous topic - next topic

maxima_diesel

Dec 03, 2012, 08:20 pm Last Edit: Dec 03, 2012, 08:22 pm by maxima_diesel Reason: 1
Hi guys I have a laboratory monitoring sensor system project which involves multiple humidity and temperature sensors hooked up to an arduino. There are three stations in the system:

main station is an arduino mega with a xbee module, TFT LCD touch screen and a DHT22 sensor connected
1st station is an arduino uno with a xbee module and a Dallas DS18B20 sensor connected to it
2nd station is an arduino uno with a xbee module a DHT22 sensor and DS18B20 sensor

Basically, I got the main station and 1st station communicating properly via the Xbee modules in API mode. I will add the 2nd station in the same configuration in the future. Basically, the TFT LCD screen is connected to the arduino mega via I2C. The communication between the TFT and the Arduino is functioning properly. My issue now is that I would like to know how to detect a string coming in the I2C bus on the Arduino mega and then perform an action/function based on it.

For example:

The user has pressed a button to change the monitor frequency of the system for the main station so the string "MON,500" will be sent via the I2C bus. The Arduino will scan the string and detect "MON" then call the appropriate function for it and then use the value after the comma as the monitor frequency value (possibly store it in the appropriate int variable).

I know that the strtok() function can be used to separate strings by detecting delimiters but I am not sure how to implement the above situation on Arduino. Thanks and Regards to everyone.

PaulS

Quote
I know that the strtok() function can be used to separate strings by detecting delimiters but I am not sure how to implement the above situation on Arduino.

Just like on any other platform.

Show your code (using the # icon).

majenko

Why suffer the complexity of strtok?

Code: [Select]


char *incoming = "MON,500";
int value = 0;

if (strncmp(incoming, "MON,", 4) == 0) {
    value = atoi(incoming + 4);
}
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

holmes4

Start with just an Uno and the USB. Send data with the serial monitor. Write code with deals with the input from the Usb on serial and does something with it (maybe just echoing to start with). Once you have the hang of this you can move on to doing the same with I2c/SPI etc.

Mark

Go Up