Pages: [1]   Go Down
Author Topic: String Detection/Manipulation question  (Read 234 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: December 03, 2012, 02:22:32 pm by maxima_diesel » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why suffer the complexity of strtok?

Code:

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

if (strncmp(incoming, "MON,", 4) == 0) {
    value = atoi(incoming + 4);
}
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 25
Posts: 1872
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: