Show Posts
|
|
Pages: [1] 2
|
|
1
|
Using Arduino / Networking, Protocols, and Devices / Re: Software Serial Two Port Recieve with GPS and Xbee
|
on: February 01, 2013, 04:05:15 pm
|
More and more, Arduinos are coming with multiple hardware serial ports. The Mega would allow you to have both devices connected to hardware serial ports and still be able to talk to the PC on Serial.
Sounds good! In this instance my brief includes small (I'm putting them inside things) and cheap (making several of them), but it's a good point and could be a useful reminder for future projects - thanks!
|
|
|
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / Re: Software Serial Two Port Recieve with GPS and Xbee
|
on: January 31, 2013, 06:16:43 am
|
Ah, thanks PaulS, that triggered a memory for me and I went back to the Arduiniana nss documentation and I think I understand now. So, whereas with a single serial source the incoming data gets buffered (is that the right word?) and it'll sit there until the loop comes around to it again, with two sources the buffer gets emptied when you switch to listening to a different device, so the signal only gets heard if it arrives during the time when the arduino is explicitly listening to it. So, I need to repeat my broadcast at a frequency that's shorter than the amount of time I'm listening. For example I changed the code to XbeeSerial.listen(); Serial.println("listening to xbee"); for (unsigned long start = millis(); millis() - start < 3000;) { } // get any incoming data from xbee: if (XbeeSerial.available() > 0) { Serial.print("Xbee data: "); // read a byte inByte = XbeeSerial.read(); Serial.println(inByte); }
else { Serial.println("Xbee data not available"); } And prodded at the number keys at about 1Hz. This seems to work. (Think I'm going to need another Arduino on the broadcasting end, though!) Thanks for pointing me in the right direction!
|
|
|
|
|
3
|
Using Arduino / Networking, Protocols, and Devices / Software Serial Two Port Recieve with GPS and Xbee
|
on: January 30, 2013, 02:10:09 pm
|
I'm using a RBBB and trying to alternately read in from a GPS module (using the TinyGPS library) and an Xbee, both over SoftwareSerial. I'm aware of http://arduino.cc/en/Tutorial/TwoPortReceive and have previously used this method to successfully read in from two GPS modules, however I don't seem to be able to get the GPS and Xbee combination working. For this stripped down version of the code I'd like to see output to serial monitor similar to the following if I send a '1' and then a '2' via XBee: . . . listening to xbee Xbee available 1 read gps time: 18584900, pos (f): 51.xxxxxx, -2.xxxxxx listening to xbee Xbee available 2 read gps time: 18585000, pos (f): 51.xxxxxx, -2.xxxxxx . . . etc However, this is what I get: . . . listening to xbee Xbee data not available read gps time: 18585000, pos (f): 51.xxxxxx, -2.xxxxxx listening to xbee Xbee data not available read gps time: 18585300, pos (f): 51.xxxxxx, -2.xxxxxx . . . I can get the GPS data, but not the Xbee. (I've checked the Xbee wiring etc). Everything I've tried gives me that 'Xbee data not available' debugging line. Here's the code: #include <SoftwareSerial.h> //includes the software serial library #include <TinyGPS.h> // includes the TinyGPS library
/* Based on TinyGPS by Mikal Hart */
TinyGPS gps; SoftwareSerial gpsmodule(10, 9); SoftwareSerial XbeeSerial(4, 3);
// a byte to receive data: char inByte = 0;
//some variables...
float flat, flon; // +/- latitude/longitude in degrees unsigned long date, time, age; // what they say on the tin long lat, lon; // +/- lat/long in 100000ths of a degree
int GPSpower = 6;
void setup() //this section of code runs once when you start the microcontroller { Serial.begin(115200); // serial communication between the microcontroller and the computer gpsmodule.begin(4800); // serial communication between the gps module and the microcontroller XbeeSerial.begin(9600);
pinMode(GPSpower, OUTPUT); digitalWrite(GPSpower, HIGH); } //end setup
void loop() //this section of code runs ad infinitum, looping until you make it stop { XbeeSerial.listen(); Serial.println("listening to xbee"); // get any incoming data from xbee: if (XbeeSerial.available() > 0) { Serial.println("Xbee available"); // read a byte inByte = XbeeSerial.read(); Serial.println(inByte); }
else { Serial.println("Xbee data not available"); }
bool newData = false; unsigned long chars; unsigned short sentences, failed;
// For one second we parse GPS data and report some key values Serial.println("read gps "); gpsmodule.listen(); for (unsigned long start = millis(); millis() - start < 1500;) { while (gpsmodule.available()) { char c = gpsmodule.read(); // Serial.write(c); // uncomment this line if you want to see the GPS data flowing if (gps.encode(c)) // Did a new valid sentence come in? newData = true; }
}
if (newData) { Serial.print("time: "); gps.get_datetime(&date, &time, &age); Serial.print(time); Serial.print(", "); Serial.print("pos (f): "); gps.f_get_position(&flat, &flon, &age); Serial.print(flat, 6); Serial.print(", "); Serial.println(flon, 6);
} //end newData
} //end loop
Have I messed up on the 2 port receive implementation somewhere? Thanks.
|
|
|
|
|
5
|
Using Arduino / Networking, Protocols, and Devices / Re: XBee responding to previous character
|
on: January 30, 2013, 09:28:04 am
|
I moved everything into the if (XbeeSerial.available() > 1) { statement and I think it's now doing what you think it's doing - just one response for every key pressed (the original code repeats the output until another key press) Terminal output looks like this (I hit enter a few times at the start) misc .misc .0misc .10 .21 .32 .4misc .5misc .0misc .10 .21 .32 .4misc .#include <SoftwareSerial.h> //includes the software serial library #include <TinyGPS.h> // includes the TinyGPS library
SoftwareSerial XbeeSerial(9, 10);
// a byte to receive data: char inByte = 0;
int Xbeepower = 6;
void setup() { Serial.begin(115200); XbeeSerial.begin(9600); pinMode(Xbeepower, OUTPUT); digitalWrite(Xbeepower, HIGH); } //end setup
void loop() {
// get any incoming data from xbee: if (XbeeSerial.available() > 1) { // read a byte inByte = XbeeSerial.read();
if (inByte == '0') { Serial.println("0"); XbeeSerial.println("0"); }
else if (inByte == '1') { Serial.println("1"); XbeeSerial.println("1"); }
else if (inByte == '2') { Serial.println("2"); XbeeSerial.println("2"); }
// do nothing if anything else was received else {
Serial.println("misc"); XbeeSerial.println("misc"); }
}
delay(200);
} //end loop
|
|
|
|
|
7
|
Using Arduino / Networking, Protocols, and Devices / XBee responding to previous character
|
on: January 30, 2013, 08:28:29 am
|
Hi, This is kind of a follow on to a previous thread, but with different hardware and a bit more detail... This time I'm using an XBee Series 2 Co-ordinator connected to my laptop via a XBee Explorer USB and the corresponding router is connected to a Real Bare Bones Board in turn connected to my laptop via USB. RO/ Packetisation Timeout is set to 0 The sketch I'm running should echo back the number sent for 1-3 and 'misc' for everything else. With the code below, I'm finding that when I send a digit the first one doesn't have an effect, and thereafter each digit sent triggers the appropriate response to the previous digit. Here's the output from the X-CTU terminal on the coordinator (red from the router, blue is what sending to the router) 0.misc .misc .10 .0 .0 .21 .1 .32 .2 .2 .2 .4misc .misc .0misc .misc .misc .10 .0 .111 .1 .221 .2 .32 .3misc .misc#include <SoftwareSerial.h> //includes the software serial library #include <TinyGPS.h> // includes the TinyGPS library
SoftwareSerial XbeeSerial(9, 10);
// a byte to receive data: char inByte = 0;
int Xbeepower = 6;
void setup() { Serial.begin(115200); XbeeSerial.begin(9600); pinMode(Xbeepower, OUTPUT); digitalWrite(Xbeepower, HIGH); } //end setup
void loop() {
// get any incoming data from xbee: if (XbeeSerial.available() > 1) { // read a byte inByte = XbeeSerial.read();
}
if (inByte == '0') { Serial.println("0"); XbeeSerial.println("0"); }
else if (inByte == '1') { Serial.println("1"); XbeeSerial.println("1"); }
else if (inByte == '2') { Serial.println("2"); XbeeSerial.println("2"); }
// do nothing if anything else was received else {
Serial.println("misc"); XbeeSerial.println("misc"); }
delay(2000);
} //end loop
So, sending each digit twice kind of works as a workaround, but it would be good to understand what's causing this and, ideally, just send each digit once. (I'm hoping to build up to sending arrays.) Am I sending the digits in the wrong format or something like that? Thanks
|
|
|
|
|
9
|
Using Arduino / Programming Questions / combining content of two character arrays
|
on: September 04, 2012, 12:50:25 pm
|
Hi, I'm developing a sketch to randomly select from a pool of messages and then send it as a tweet. I've the basics all working (ethernet shield, saving messages to PROGMEM, randomly retrieving one of them, tweeting it), but in order to avoid Twitter rejecting duplicate messages I'd like to add an incrementor to the beginning of the message that gets tweeted. I've managed to get the incrementor incrementing and then put the resulting int into a character array - which then gets successfully tweeted - but I'm struggling to get the bit where I need to add the message into the tweet content working. Here's a stripped down version of the code I'm currently arrived at: #include <SPI.h> // needed in Arduino 0019 or later #include <Ethernet.h> #include <Twitter.h> #include <avr/pgmspace.h> #include <SoftwareSerial.h>
int copiercount = 0; //[message contents saved to PROGMEM here] //[ lookup table here]
char buffer[140]; // make sure this is large enough for the largest string it must hold
//[ethernet settings etc]
// Message to post char msg[145] ;
void setup() { //[communications set up etc ] }
void sendtweet(){ // [code to send tweet here ] }
void loop() { copiercount = copiercount + 1; Serial.println("Select from copier pool ");
strcpy_P(buffer, (char*)pgm_read_word(&(copier_table[randNumber]))); // Necessary casts and dereferencing, just copy. Serial.println( buffer ); Serial.print("copier count: "); Serial.println( copiercount );
String stringOne = "> "; stringOne += copiercount; char counter[5]; stringOne.toCharArray(counter, 5) ;
msg[0] = counter[0]; msg[1] = counter[1]; msg[2] = counter[2]; msg[3] = counter[3]; msg[4] = counter[4];
for (int j = 5; j < 143; j++){ msg[j] = buffer[j-5];} Serial.println( msg ); sendtweet();
Serial.println(); } //end loop
This is outputting a series of tweets with the content "> 1", "> 2" etc, but not adding in the main body of the message afterwards. I'd be grateful if someone could explain to me where I'm going wrong and/or the correct way to combine the two segments of the tweet content. My programming knowledge is limited, so please don't assume much in the way of prior knowledge! Thanks.
|
|
|
|
|
11
|
Using Arduino / Networking, Protocols, and Devices / Switching XBee coordinator modems
|
on: June 25, 2012, 05:01:00 am
|
|
Hi,
I've a little experience with XBee that suggests this might be possible, but I wanted to get some feedback here too...
I want to have a network of Series 2 XBees (routers, probably) receiving data broadcast from a coordinator modem.
So far so good.
But what I now want to be able to do is have a choice of 3 coordinator modems - only one on at a time, but to switch between them periodically. So, I'd have the network set up as described, power down one coordinator modem and power up a different one instead. Rinse and repeat. Is this possible? Will the network continue to function?
Thanks
|
|
|
|
|
12
|
Using Arduino / Networking, Protocols, and Devices / Re: XBee and ATtiny - delays in responses
|
on: April 21, 2012, 09:17:49 am
|
Partial success! Adding a 16Mz external clock was as simple as adding the following to boards.txt in the hardware folder: attiny45-16.name=ATtiny45 (external 16 MHz clock) attiny45-16.bootloader.low_fuses=0xfe attiny45-16.bootloader.high_fuses=0xdf attiny45-16.bootloader.extended_fuses=0xff attiny45-16.upload.maximum_size=4096 attiny45-16.build.mcu=attiny45 attiny45-16.build.f_cpu=16000000L attiny45-16.build.core=arduino:arduino attiny45-16.build.variant=tiny8 However it doesn't seem to make any difference to the response to the incoming XBee data - I still need to send "0" or "1" twice before the LED changes state.
|
|
|
|
|
14
|
Using Arduino / Networking, Protocols, and Devices / Re: XBee and ATtiny - delays in responses
|
on: April 18, 2012, 06:47:53 am
|
Still learning how to read pinout diagrams... Are MOSI and MISO on the ATtiny equivalent to RX and TX on pins 0 and 1 on the Arduino? (Or are you saying it's something different, PaulS?) Would I be right in thinking that to add an external clock to the ATtiny45 I put a crystal across physical pins 2 and 3, with caps between 2 and 4 and 3 and 4? [ datasheet] I have some 16MHz crystals and 22pF caps from making breadboard arduinos, can I use them? I notice the list in the IDE under tools > board only has an option for a 20MHz external clock... This is the chip I'm using: http://uk.rs-online.com/web/p/microcontroller/6962614/...and would I need to do anything to undo the 8MHz bootloader command step I did before?
|
|
|
|
|
15
|
Using Arduino / Networking, Protocols, and Devices / XBee and ATtiny - delays in responses
|
on: April 18, 2012, 04:02:29 am
|
Hi, What I'm working towards is having an Arduino + XBee coordinator reading GPS data and then broadcasting data (probably a digit 0-9) to a network of ATtiny + XBee router nodes which will then trigger vibration motors in response. I currently have an XBee coordinator attached to my laptop and X-CTU via an XBee Explorer. I'm using the keyboard to send 0s and 1s to a router XBee. The router is attached to an ATtiny45 on a breadboard, currently powered by an Arduino UNO as per the programming set up as per the MIT tutorial. I've run the burn bootloader command to set it to run at 8MHz and the XBee is connected via software serial. There's an LED on Pin 4 and I'm running this code: #include <SoftwareSerial.h> SoftwareSerial XbeeSerial(0, 1); int outputPin = 4;
// a byte to receive data: char inByte = 0;
void setup () { // set pins to input and output appropriately pinMode(outputPin, OUTPUT);
// start up the serial connection XbeeSerial.begin(9600); }
void loop () {
// get any incoming data: if (XbeeSerial.available() > 1) { // read a byte inByte = XbeeSerial.read(); // light the LED if a 1 has been received } if (inByte == '1') { digitalWrite(outputPin, HIGH);
} // douse the LED if anything else was received else if (inByte == '0'){ digitalWrite(outputPin, LOW); } } It's kind of working - so when I send a 1 the LED lights and when I send a 0 it turns off ...except in practice I'm finding I need to send a couple of 1s or 0s for a change to take place and there can be delays of several seconds. Ideally I'd like to send a single digit and for the response to be instant. I'm new to both XBees and ATtiny, can anyone suggest how to get this please? I already have the XBees configured with packetization timeout (AT RO) set to 0. Is there anything else I should change either in the modem set-up or with the ATtiny chip, perhaps? Thanks, nikki
|
|
|
|
|