Home › Forums › Other Data Loggers › Seeeduino Stalker v3.0 discussion › Reply To: Seeeduino Stalker v3.0 discussion
I’m not sure why your code didn’t post correctly. Maybe because you attached it as a .ino file. Try just pasting it into the “code snippet” box when you’re typing a reply. Just hit the “Add Code Snippet” button in the row of buttons right above the text box, past your code into the window that pops up and choose “Arduino” from the Language drop-down menu so it formats the code properly.
Here’s some code that I used a long time ago when using the Maxbotix sensors with a Seeeduino Stalker. In the example, I connected the data line of the sensor to pin D7, then just connect the sensor to ground and its power to 3v3. Communicating with the Maxbotix sensor only uses pin 5, 6, and 7 on the sensor. The sensor outputs a digital string every second when it’s powered continuously. If you only want to take readings periodically, you can power the sensor momentarily with any of the free digital pins on the Stalker since the sensor only uses a few milliamps so the Arduino digital pins can source that. In the following example, it’s powered all the time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
/* test function to Parse data from MaxSonar serial data and return integer */ #include <SoftwareSerial.h> SoftwareSerial sonarSerial(7, -1); //define serial port for recieving data boolean stringComplete = false; void setup() { Serial.begin(9600); //start serial port for display sonarSerial.begin(9600); //start serial port for maxSonar delay(100); } void loop() { int range = EZread(); if(stringComplete) { stringComplete = false; //reset sringComplete ready for next reading Serial.print("Range: "); Serial.println(range); Serial.println(" mm"); delay(1000); //delay 1 second } } int EZread() { int result; char inData[6]; //char array to read data into int index = 0; sonarSerial.flush(); // Clear cache ready for next reading while (stringComplete == false) { //Serial.print("reading "); //debug line if (sonarSerial.available()) { char rByte = sonarSerial.read(); //read serial input for "R" to mark start of data if(rByte == 'R') { //Serial.println("rByte set"); while (index < 5) //read next three character for range from sensor { if (sonarSerial.available()) { inData[index] = sonarSerial.read(); //Serial.println(inData[index]); //Debug line index++; // Increment where to write next } } inData[index] = 0x00; //add a padding byte at end for atoi() function } rByte = 0; //reset the rByte ready for next reading index = 0; // Reset index ready for next reading stringComplete = true; // Set completion of read to true result = atoi(inData); // Changes string data into an integer for use } } return result; } |