Show Posts
|
|
Pages: [1] 2
|
|
2
|
Using Arduino / Programming Questions / Socket Programming Question?
|
on: August 28, 2012, 01:42:33 pm
|
I wanna send data from PC to an Arduino+Ethernet Shield, I am using sockets, and coding program in C# as client, I can send data and read it on serial monitor, but whenever I send more than character from the PC I get this : If I send one character ex"1", I get on the serial monitor : Value received 1 but if I send multiple character "120", I get this : Value received: 1 Value received: 2 Value received: 0 C# send code : void Button3Click(object sender, EventArgs e) {
byte[] fwd = Encoding.ASCII.GetBytes("120"); int bytesSent = sock.Send(fwd);
} Arduino code : EthernetClient client = server.available(); while (client.connected()) { if (client.available()) { char c = client.read(); Serial.print("Value received: "); Serial.println(c); I wanna get "120" in serial monitor not 1 then 2 then 0... Is it and Arduino Coding problem or C#?
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Re: Tiny GPS + Ethernet Shield
|
on: August 27, 2012, 01:07:57 am
|
ok, I've already have some experience in sending data using a web server, and I've used the code you posted to send a tempreture sensor data to a web browser, but I have no idea how to write the GPS data, that uses the Tiny GPS library, into the web browser? here's the GPS code: #include <SoftwareSerial.h> #include <TinyGPS.h>
/* This sample code demonstrates the normal use of a TinyGPS object. It requires the use of SoftwareSerial, and assumes that you have a 4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx). */
TinyGPS gps; SoftwareSerial nss(3, 4);
static void gpsdump(TinyGPS &gps); static bool feedgps(); static void print_float(float val, float invalid, int len, int prec); static void print_int(unsigned long val, unsigned long invalid, int len); static void print_date(TinyGPS &gps); static void print_str(const char *str, int len);
void setup() { Serial.begin(115200); nss.begin(4800); Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version()); Serial.println("by Mikal Hart"); Serial.println(); Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS)); Serial.println(); Serial.println("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"); Serial.println(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"); Serial.println("--------------------------------------------------------------------------------------------------------------------------------------"); }
void loop() { bool newdata = false; unsigned long start = millis(); // Every second we print an update while (millis() - start < 1000) { if (feedgps()) newdata = true; } gpsdump(gps); }
static void gpsdump(TinyGPS &gps) { float flat, flon; unsigned long age, date, time, chars = 0; unsigned short sentences = 0, failed = 0; static const float LONDON_LAT = 51.508131, LONDON_LON = -0.128002; print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5); print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5); gps.f_get_position(&flat, &flon, &age); print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5); print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5); print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
print_date(gps);
print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2); print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2); print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2); print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6); print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0UL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9); print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128002), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2); print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);
gps.stats(&chars, &sentences, &failed); print_int(chars, 0xFFFFFFFF, 6); print_int(sentences, 0xFFFFFFFF, 10); print_int(failed, 0xFFFFFFFF, 9); Serial.println(); }
static void print_int(unsigned long val, unsigned long invalid, int len) { char sz[32]; if (val == invalid) strcpy(sz, "*******"); else sprintf(sz, "%ld", val); sz[len] = 0; for (int i=strlen(sz); i<len; ++i) sz[i] = ' '; if (len > 0) sz[len-1] = ' '; Serial.print(sz); feedgps(); }
static void print_float(float val, float invalid, int len, int prec) { char sz[32]; if (val == invalid) { strcpy(sz, "*******"); sz[len] = 0; if (len > 0) sz[len-1] = ' '; for (int i=7; i<len; ++i) sz[i] = ' '; Serial.print(sz); } else { Serial.print(val, prec); int vi = abs((int)val); int flen = prec + (val < 0.0 ? 2 : 1); flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1; for (int i=flen; i<len; ++i) Serial.print(" "); } feedgps(); }
static void print_date(TinyGPS &gps) { int year; byte month, day, hour, minute, second, hundredths; unsigned long age; gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age); if (age == TinyGPS::GPS_INVALID_AGE) Serial.print("******* ******* "); else { char sz[32]; sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ", month, day, year, hour, minute, second); Serial.print(sz); } print_int(age, TinyGPS::GPS_INVALID_AGE, 5); feedgps(); }
static void print_str(const char *str, int len) { int slen = strlen(str); for (int i=0; i<len; ++i) Serial.print(i<slen ? str[i] : ' '); feedgps(); }
static bool feedgps() { while (nss.available()) { if (gps.encode(nss.read())) return true; } return false; } I wanna see the same results I am getting on the serial monitor but this time on a web browser.. Here, we have serial.print used in a function not in the main loop, that's why I am a little bit confused!
|
|
|
|
|
7
|
Using Arduino / Programming Questions / Tiny GPS + Ethernet Shield
|
on: August 26, 2012, 01:28:59 pm
|
|
anyone have an idea about sending data of a GPS from Arduino+Ethernet Shield to a web browser? I have parallax PMB-688 GPS module, Arduino UNO & Ethernet Shield. over serial the GPS works perfectly using Tiny GPS, but I need to send those GPS data to the web browser. is it gonna work?
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Re: Arduino GPS Shield by iteadstudio.com
|
on: August 14, 2012, 10:57:47 am
|
the code you're using is for the GPS shield by iteadstudio.com you're using another shield, try this code : /* 6-8-10 Aaron Weiss SparkFun Electronics Example GPS Parser based off of arduiniana.org TinyGPS examples. Parses NMEA sentences from an EM406 running at 4800bps into readable values for latitude, longitude, elevation, date, time, course, and speed. For the SparkFun GPS Shield. Make sure the switch is set to DLINE. Once you get your longitude and latitude you can paste your coordinates from the terminal window into Google Maps. Here is the link for SparkFun's location. http://maps.google.com/maps?q=40.06477,+-105.20997 Uses the NewSoftSerial library for serial communication with your GPS, so connect your GPS TX and RX pin to any digital pin on the Arduino, just be sure to define which pins you are using on the Arduino to communicate with the GPS module. REVISIONS: 1-17-11 changed values to RXPIN = 2 and TXPIN = to correspond with hardware v14+. Hardware v13 used RXPIN = 3 and TXPIN = 2. */
// In order for this sketch to work, you will need to download // TinyGPS library from arduiniana.org and put them // into the hardware->libraries folder in your ardiuno directory. #include <SoftwareSerial.h> #include <TinyGPS.h>
// Define which pins you will use on the Arduino to communicate with your // GPS. In this case, the GPS module's TX pin will connect to the // Arduino's RXPIN which is pin 3. #define RXPIN 2 #define TXPIN 3 //Set this value equal to the baud rate of your GPS #define GPSBAUD 4800
// Create an instance of the TinyGPS object TinyGPS gps; // Initialize the NewSoftSerial library to the pins you defined above SoftwareSerial uart_gps(RXPIN, TXPIN);
// This is where you declare prototypes for the functions that will be // using the TinyGPS library. void getgps(TinyGPS &gps);
// In the setup function, you need to initialize two serial ports; the // standard hardware serial port (Serial()) to communicate with your // terminal program an another serial port (NewSoftSerial()) for your // GPS. void setup() { // This is the serial rate for your terminal program. It must be this // fast because we need to print everything before a new sentence // comes in. If you slow it down, the messages might not be valid and // you will likely get checksum errors. Serial.begin(115200); //Sets baud rate of your GPS uart_gps.begin(GPSBAUD); Serial.println(""); Serial.println("GPS Shield QuickStart Example Sketch v12"); Serial.println(" ...waiting for lock... "); Serial.println(""); }
// This is the main loop of the code. All it does is check for data on // the RX pin of the ardiuno, makes sure the data is valid NMEA sentences, // then jumps to the getgps() function. void loop() { while(uart_gps.available()) // While there is data on the RX pin... { int c = uart_gps.read(); // load the data into a variable... if(gps.encode(c)) // if there is a new valid sentence... { getgps(gps); // then grab the data. } } }
// The getgps function will get and print the values we want. void getgps(TinyGPS &gps) { // To get all of the data into varialbes that you can use in your code, // all you need to do is define variables and query the object for the // data. To see the complete list of functions see keywords.txt file in // the TinyGPS and NewSoftSerial libs. // Define the variables that will be used float latitude, longitude; // Then call this function gps.f_get_position(&latitude, &longitude); // You can now print variables latitude and longitude Serial.print("Lat/Long: "); Serial.print(latitude,5); Serial.print(", "); Serial.println(longitude,5); // Same goes for date and time int year; byte month, day, hour, minute, second, hundredths; gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths); // Print data and time Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/"); Serial.print(day, DEC); Serial.print("/"); Serial.print(year); Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); Serial.print("."); Serial.println(hundredths, DEC); //Since month, day, hour, minute, second, and hundr // Here you can print the altitude and course values directly since // there is only one value for the function Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude()); // Same goes for course Serial.print("Course (degrees): "); Serial.println(gps.f_course()); // And same goes for speed Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph()); Serial.println(); // Here you can print statistics on the sentences. unsigned long chars; unsigned short sentences, failed_checksum; gps.stats(&chars, &sentences, &failed_checksum); //Serial.print("Failed Checksums: ");Serial.print(failed_checksum); //Serial.println(); Serial.println(); } hope you it works ..
|
|
|
|
|
10
|
Using Arduino / Networking, Protocols, and Devices / Re: Arduino doesn't get ip
|
on: July 20, 2012, 05:34:03 pm
|
Hey there, i think your problem is here if (Ethernet.begin(mac) == 0) { Serial.println("DHCP FAILED"); //Use a fixed IP address, as determined above Ethernet.begin(mac, ip); } remove the if ( Ethernet. begin(mac)==0) statement and just use Ethernet.begin(mac,ip); so your void setup must look like this void setup() { //Start Hardware Serial Serial.begin(9600); //Start SoftwareSerial Xbee communications xbee.begin(9600);
//Start the Ethernet connection Ethernet.begin(mac, ip); //Print the obtained IP address (for debugging) Serial.print("Client is at "); Serial.println(Ethernet.localIP()); pinMode(5, OUTPUT); pinMode(3, OUTPUT); digitalWrite(5, HIGH); digitalWrite(3, LOW); //tx 7 //5v 5 //gnd 3 wdt_enable(WDTO_8S);
} hope it works.
|
|
|
|
|
13
|
Using Arduino / Project Guidance / Re: Arduino + Android
|
on: July 12, 2012, 08:37:11 am
|
Practically you're idea will work, you will need relays to control home equipments... I think, you should buy Arduino Uno, great and easy for beginners. as for Android there's Amarino toolkit, its open source too http://www.amarino-toolkit.net/... as for Amarino it uses Bluetooth connection, for WiFi, you will need a WiFi shield or an Ethernet shield connected to a router.. you can control your Arduino using a web interface, or socket connection( I don't know if socket works )... I am new to Arduino too, just bought mine 1 month ago...
|
|
|
|
|
14
|
Using Arduino / Project Guidance / Re: Arduino+GPS to Android App (Network robot)
|
on: July 11, 2012, 11:24:44 am
|
|
as for the Ethernet, i am good in using Arduino as web server, i am gonna use TinyGPS to extract the latitude and longitude.. as for the gps, i am gonna use the Parallax PMB-688...i only need latitude and longitude for my project...and my robot isn't gonna be that fast... I am gonna use the Android app just for control and monitoring(I am not gonna connect my Arduino to the Android phone), so i don't need an Arduino ADK, right?
Does the Arduino Ethernet Shield work in the same way with Arduino Mega as like UNO? or are there some difference in the pins connections or code modifications?
Regards
|
|
|
|
|
15
|
Using Arduino / Project Guidance / Arduino+GPS to Android App (Network robot)
|
on: July 11, 2012, 10:23:36 am
|
|
I am planing to build a robot, that i can control using an Android app and draw the map of motion of the robot on the Android "using google map library" the robot includes : 2 servo motors, a GPS, Ultrasonic Range Finder, temperature sensor and a voltage monitor. for the voltage monitor, i am gonna use a voltage divider temperature sensor : LM35 Ultrasonic Range Finder : Parallax PING))) As for Arduino: I am gonna use arduino UNO + Ethernet Shield, connected to an on board WIFI router
The objective is to send the sensor data to Android, and in particular the longitude and latitude are gonna be used as entries for google map library..
I am confused, should i replace the Arduino uno by an Arduino mega? do you think i am gonna face problems sending the GPS data on Ethernet and what is the best GPS to use? i am interested in Parallax PMB-688 GPS receiver module...
Any suggestions would be greatly appreciated !
|
|
|
|
|