Finished OLED/GPS example

Finished up the OLED/GPS setup, this uses a black rectangle to erase only portions of the screen where I want the text to be updated. It seems to minimize the flicker seen in the previous example. The video cuts because it takes 5-10 minutes for my GPS to start receiving from the satellites, which may have been a slightly ginormous video file to upload.

A few things to note, when using the print or println in the GFX library each character takes up 5×8 pixels(but can be biggie-sized, just look at the documentation). So the letter A printed on the first line at cursor position x=0, y=0 would end at x=5, y=8. This is useful if you want to erase just that letter. A black rectangle drawn from x=0, y=0 to x=5,y=8 would cover that entire letter. The code for that would look like this display.fillRect(0,0,5,8,BLACK); where the rectangle starts at 0,0 and ends at 5,8 with a color of Black.

The display I used is 0.96″ containing 96 pixels across, 64 down. So the center of the display is at 48,32.

This code displays a circle starting at pixel x=5, y=5 with a radius of 4. So it ends at x=9, y=9. I start my text at x=0, y=10 in order to prevent overlap.

1
2
3
4
5
   if(gps.satellites.value()<=2){     //Displays a small circle, yellow or green depending upon # of satellites acquired
    display.fillCircle(5,5,4,YELLOW);
  } else {
   display.fillCircle(5,5,4,GREEN);   //Same as the above except displays a green circle for more than 2 satellites
 }

For printing the # of satellites, latitude, and longitude the code looks like the below. This starts out by printing out a line of text, starting at x=0, y=26. This is 10 characters in length(including the space at the end), so I set the rectangle to draw at position x=50, y=26. Five pixels across multiplied by 10 is the 50th pixel in the X direction. Because I used print for the “Longitude”, when I print the gps.location.lng() its already at the x=50, y=26 position.

1
2
3
4
display.setCursor(0,26);
display.print("Longitude ");
display.fillRect(50,26,5,8,BLACK);
display.println(gps.location.lng());

Components
Arduino Uno
0.96″ OLED Breakout board from Adafruit
GP-635T GPS Module from Sparkfun

Full working example. See Adafruit.com for how to connect the OLED. GPS is connected to the Arduino Uno on TX/RX pins 0 and 1. One note, if you receive any errors like the following, its due to how the Arduino/GPS are connected, something about TX/RX interfering with the upload. Disconnecting the power to the GPS during the upload to the Uno should resolve the problem.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <TinyGPS++.h>     //TinyGPS library
#include <SoftwareSerial.h>   //Software serial library
#include <Adafruit_GFX.h>     //GFX library, from Adafruit
#include <Adafruit_SSD1331.h>   //Library for the OLED display I used. See the Adafruit product page for more info,
                                //can change depending upon the display used.
#include <SPI.h>

#define sclk 13    //next 5 lines define the pins for the OLED display. From the Adafruit GFX library
#define mosi 11
#define cs   10
#define rst  9
#define dc   8
 
                   //Defining the possible colors that can be used. From the Adafruit GFX library
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF



                                           
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);  //define the display object

static const int RXPin = 0, TXPin = 1;  //RX and TX pins, connected to the Uno pins 0 1
static const uint32_t GPSBaud = 9600;  //Defining the GPS baud

                       
TinyGPSPlus gps;                         //Define the GPS object
                                         
SoftwareSerial ss(RXPin, TXPin);         //setting up the connection to the GPS using the Software serial library

void setup()
{
  ss.begin(GPSBaud);                    
  display.begin();                     //Initialize the display
  display.fillScreen(BLACK);           //Initialize the display, set it to black(makes sure that any artifacts are removed
  display.setCursor(0,0);              //Set the cursor to the top left corner
 
}

void loop()
{                                     //While loop displays an animated circle as the GPS waits on connection to satellites
   while(gps.satellites.value()==0){  
     display.fillCircle(48,32,10,RED);
     for(int i=5;i<35;i+=5){          
     display.drawCircle(48,32,i,RED);
   }
   smartDelay(1000);                  
   display.fillScreen(BLACK);        
 }                                    

   if(gps.satellites.value()<=2){     //Displays a small circle, yellow or green depending upon # of satellites acquired
    display.fillCircle(5,5,4,YELLOW);
  } else {
   display.fillCircle(5,5,4,GREEN);   //Same as the above except displays a green circle for more than 2 satellites
 }
                     
  display.setCursor(0,10);            
  display.print("Sats= ");            
                                     

  display.fillRect(30,10,6,8,BLACK);  //In order to erase only the # of satellites and not the entire line of text
  display.setCursor(31,10);           //this draws a black rectangle over pixels from x=30, y=10 with a width of 6 and height of 8
  display.println(gps.satellites.value());

  display.setCursor(0,18);            
  display.print("Latitude ");        
  display.fillRect(45,18,5,8,BLACK);
  display.println(gps.location.lat());
 
 
  display.setCursor(0,26);
  display.print("Longitude ");
  display.fillRect(50,26,5,8,BLACK);
  display.println(gps.location.lng());
 
 
  smartDelay(1000);
   if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
   
}
                                                           
                 
static void smartDelay(unsigned long ms)     //Reads string from the GPS device
{
  unsigned long start = millis();
  do
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

20140914_011509

20140914_114134

Arduino GPS with OLED Display

An attempt at scaling down the GPS logger I made, this one is using a mini GPS receiver from Sparkfun with coordinates displayed on a 0.96″ OLED from Adafruit. It’s still a work in progress just squishing together code from the TinyGPS++ library and using the Adafruit GFX Library

Right now it’s refreshing the entire screen as the coordinates are updated, the plan is to adjust the cursor position and only rewrite the Latitude/Longitude coordinates. The image with the yellow dot will be for when the GPS unit is waiting on satellites(usually takes a few minutes to get a satellite lock) though it’ll probably be a little animated display since that just looks spiffier. So far the only problem is the refresh of the screen. Even without a delay(x) it still has a noticeable flash as the screen is drawn. Though this is most likely because I’ve never used the GFX library before yesterday.

Strangely the GP-635 is hitting 7 satellites while the GPS I used in the data logger was only getting 3, despite both sitting in my apartment with no external antenna attached.

Components:

Arduino Uno
GPS Receiver: GP-635T from Sparkfun
Display: 16 bit color 0.96″ OLED Breakout Board from Adafruit

gp635

connecting

GPS coordinates displayed on a.96" OLED using an Arduino Uno

GPS coordinates displayed on a.96″ OLED using an Arduino Uno

Working code is below, no comments in the code yet except those that exist in the GFX & TinyGPS example code. The GPS RX/TX are connected to Digital Pins 0 & 1 on the Arduino Uno with Vcc connected to 5V, and of course don’t forget to connect the GND. The wiring of the display is shown on the Adafruit site at the link above.

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define sclk 13
#define mosi 11
#define cs   10
#define rst  9
#define dc   8
/*
   This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1331.h>
#include <SPI.h>
int numSats;
// Option 1: use any pins but a little slower
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);  
int i=1;
static const int RXPin = 0, TXPin = 1;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
   ss.begin(GPSBaud);
  display.begin();
  display.fillScreen(BLACK);
  display.setCursor(0,0);
 
}

void loop()
{
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  numSats=gps.satellites.value();
 
  //display.fillScreen(BLACK);
  //while(gps.satellites.value()==0){

//    display.fillCircle(48,32,10,RED);
//    for(int i=5;i<35;i+=5){
//      display.drawCircle(48,32,i,RED);
//      delay(10);
//      display.fillScreen(BLACK);
//  }
// }
//  if(numSats==0){
//    display.fillCircle(5,5,4,RED);
//  }
//  if(numSats<=2){
    display.fillCircle(5,5,4,YELLOW);
//  } else {
   display.fillCircle(5,5,4,GREEN);
// }
 
if(gps.location.isUpdated()){
  display.fillScreen(BLACK);
  display.setCursor(0,9);
//  float gpsLoc=gps.location.lat();
  display.print("Number of Sats=");
  display.println(numSats);
  display.print("Latitude ");
  display.println(gps.location.lat());
  display.print("Longitude ");
  display.println(gps.location.lng());
  delay(1000);
 
}
 
  smartDelay(1000);

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

Quadcopter Update

Almost finished, took forever to get to this point after I discovered that when your only tools are a dremel and a screwdriver that it’s pretty hard to actually build anything that requires a bit of precision. So I went the quick way and got a frame from Hobbyking.com, only $17 so not a bad deal for the whole setup. Now to just mount everything and see if I can cras..er fly it…

The quadcopter, frame complete, test fitting the receiver and flight controller

The quadcopter, frame complete, test fitting the receiver and flight controller

Receiver sitting on the new frame

Receiver sitting on the new frame

Neopixel – Trying out app inventor with a bluetooth module

Yet another test with the neopixels since I’ve been bored. This one isn’t working yet but its an attempt at using an android app to program pixels on/off via a bluetooth module connected to an arduino Uno/neopixel combo. Right now I’m able to connect and send data to the arduino but its not triggering the neopixel. May need some interrupts in there, not sure yet since this is all new to me.

The basic flow of the program is Handshake with arduino via bluetooth connection >> Listen to the serial connection >> Read string >> Turn on pixel

Components
Arduino Uno
Bluetooth module(I don’t even know what I have, its basically Vcc, GND, RX, TX)
Neopixel

Programming is done using App inventor for the Android side and just a simple Arduino sketch to monitor the serial data and turn on/off the neopixel. Right now turning off a pixel is done via a long click, I may have missed if app inventor has a toggle in there. The two icons in the top left/right of the designer layout are for setting the icon to green/blue when turning them on and off(they’re both hidden, but on single click it sets the icon to one image, on long click it sets it to the other image).

App inventor designer layout

App inventor block layout. Pretty straightforward, connect to bluetooth, send via serial on click.

App inventor designer layout. Getting a nice circle shape doesn't work well(at least not without some effort)

App inventor designer layout. Getting a nice circle shape doesn’t work well(at least not without some effort)

 

 

 

 

 

 

  

 

 

  

 

 

  

Here’s some sample code for reading a string from serial and just turning the on-board LED on the Uno on/off. Taken from the Arduino website. Once I have some working code I’ll post it here.

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
int ledPin = 13;
String readString;

void setup() {
 
 Serial.begin(9600);
pinMode(ledPin,OUTPUT);
 
}


void loop() {
 
 while(Serial.available()){
 
  delay(3);
  char c=Serial.read();
  readString+=c;
}

if (readString.length() >0){{
  Serial.println(readString);
  if(readString=="on")
  {
    digitalWrite(ledPin,HIGH);
  }
  if(readString=="off")
  {
   digitalWrite(ledPin,LOW);
  }
  readString="";
 
 
 
}
}
}

Neopixel – So I broke the thumbstick code – here’s something I couldn’t break

Thumbstick codes working again
Just a short example of making a nice swirly light with the neopixel and using arrays to set brightness/color. Hopefully the video works, Roberto is watching in the background

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
//A slow moving demo of the neopixels
#include <Adafruit_NeoPixel.h>
#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);

int brgt[]={10,20,50,100,255}; //Array of brightness settings
int temppin=0;    
int pix[]={255,23,222,34,88};  //array of colors

void setup() {
 
  strip.begin();   //start the neopixel
  strip.show();   //turn all pixels off
//  Serial.begin(9600);
}


void loop() {
 
  for(int j=0;j<=15;j++){  
   strip.setBrightness(0); //turns off the pixels, without this they stay lit, set it to 50 and see
   strip.show();
   for(int i=0;i<5;i++){
     strip.setPixelColor(j,255,0,pix[i]); //looping through all the color settings
     strip.setBrightness(brgt[i]);   //looping through all the brightness settings
     strip.show();                   //needed to update the pixels
     temppin=j-1;
     strip.setPixelColor(temppin,255,0,10);  //this turns on the previous pixel, as pixel j is displayed, j-1 is lit. Move this outside the loop and it'll change things
     delay(10);                    //the delay between each brightness setting
       
 }
 }
}

The final project from a digital design class – A ginormous guide to the Fox11-68HC11 trainer board

Fox 11 board
From years ago, one of my digital design courses required us to learn assembly using the old Fox11 boards and to write up a “User Guide” on programming and setup. Managed to get about 50 pages worth of info into it but this was the initial draft, spelling/grammar mistakes and all.

I still have the board, though I don’t have any way to connect it anymore since I don’t own anything with a parallel port and Windows 8 probably won’t even recognize it. But maybe this will help someone

First page of the PDF

First page of the PDF

Fox11_68HC11

Looks like they still sell them though:
http://www.evbplus.com/hcs12_9s12_store/non-students.html

Neopixel – Using a thumbstick to control direction

A random test using a thumbstick to control the theaterchase direction and color of a 16 LED Neopixel

Components:
16 led neopixel from adafruit
Arduino Uno
Analog 2-axis Thumb Joystick

The hookup is simple, wire up Vin/GND for the neopixel and joystick, input to the neopixel is on pin 6 of the Uno. Analog pins 0 and 1 connect to the thumbstick. As the thumbstick is moved vertically the analog value is read, compared to a value somewhere in the middle, if higher it sets direction one way, lower is the reverse. I didn’t get it exact so it will always move in one direction until the joystick is moved the other direction.

strip.setPixelColor(j,pixColor);
This uses the horizontal thumbstick value, which is set to a number between 0-255, and sends that to the Wheel function from the strandtest sketch in the Neopixel library, this returns an RGB color.

[jwplayer mediaid=”231″]

np - Copy

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
#include <Adafruit_NeoPixel.h>

#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);

const int VERT = 0;    //Thumbstick connected to the Analog pin 0 on the Uno
const int HORIZ = 1;   //Thumbstick connected to the Analog pin 1 on the Uno
int pixColor;
int pixVal;
void setup() {  
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

}

void loop() {
  strip.setBrightness(20);  //sets the pixel brightness

  int vertVal, horizVal;  
  vertVal = analogRead(VERT);   //Reads the thumbstick, controls direction of pixels
  horizVal = analogRead(HORIZ);  //Controls the color

  pixVal=horizVal/2.7;  //Thumbstick values went to ~627, so this just makes sure its value is under 255
  if(pixVal>255){       //Just in case the value is > 255
    pixVal=255;
  }
  pixColor=Wheel(pixVal);   //Calls the Wheel function and sets the pixel color to the returned value
  if(vertVal>500){
     dirCounter();      //If the thumbstick value reads higher than 500, calls the dirCounter function, otherwise calls dirClock

  } else {

    dirClock();
  }
}


void dirCounter() {
    for(int j=0;j<=strip.numPixels();j++){  //strip.numPixels returns the # of leds in the neopixel
    strip.setPixelColor(j,pixColor);        //turns on each pixel, setting the color to the value returned from the Wheel function
    strip.show();
    delay(20);
    strip.setPixelColor(j,0);              //turns off the pixel before moving to the next
    strip.show();
  }
}

void dirClock() {
    for(int j=strip.numPixels();j>=0;j--){
    strip.setPixelColor(j,pixColor);
    strip.show();
    delay(20);
    strip.setPixelColor(j,0);
    strip.show();
  }
}

//Below function came from the strandtest sketch in the Neopixel library from Adafruit
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Javascript API/GPS data logger test

CaptureAn example of a KML I made using an Arduino hooked up to a data logger and a GPS module(MTK3339) from Adafruit. I turned it on when I went to/from work, the accuracy is pretty good for something that was still on a breadboard, in a box, and with no external antenna attached.
http://www.benty.org/Java/java2.html

I made up a little Fritzing schematic, not shown in this is the SD Datalogger shield from Adafruit, since there’s no schematic for it in Fritzing. The datalogging shield sits right on top of the Arduino so the connections are all the same.

Parts list:
Arduino Uno
SD Datalogging Shield
MTK3339 GPS module(There’s also a breakout board for this that would make the connections easier, since the pads on the sensor are small and solderings a bit difficult)
TMP36 analog temp sensor
Parallax Serial LCD(has 3 connections, RX/Vin/GND)
6XAA battery holder

gps_breadboarding_bb gps_logger

Here’s the code I used, I added in some comments but haven’t cleaned out the junk code I used when testing. The code calling the analog pin can be removed if there’s no temperature sensor
attached.

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include &lt;TinyGPS++.h&gt;
#include
#include
#include
#include &lt;avr/sleep.h&gt;

static const int RXPin =0, TXPin = 1; //Tx and Rx connected to the GPS module.
static const uint32_t GPSBaud = 9600;
const int TxLcdPin = 6;

#define tempPin 1 // analog 1
#define BANDGAPREF 14 // special indicator that we want to measure the bandgap
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!
#define bandgap_voltage 1.1 // this is not super guaranteed but its not -too- off
SoftwareSerial mySeriallcd = SoftwareSerial(255, TxLcdPin); //Using software serial to connect to the Parallax Serial LCD(on pin 6 of the arduino)

TinyGPSPlus gps;
const int chipSelect = 10; //Chip select for the Adafruit datalogging shield http://www.adafruit.com/products/1141
float temperatureF;

SoftwareSerial ss(RXPin, TXPin);

void setup()
{
pinMode(TxLcdPin, OUTPUT); //Set the Tx pin for the LCD to high
digitalWrite(TxLcdPin, HIGH);
mySeriallcd.begin(9600);
Serial.begin(115200);
ss.begin(GPSBaud);
pinMode(10, OUTPUT); //Set the output to the SD datalogging shield to pin 10
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");

return;
}
Serial.println("card initialized."); //code from the TinyGPS ++ library
Serial.println(F("FullExample.ino"));
Serial.println(F("An extensive example of many interesting TinyGPS++ features"));
Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F("by Mikal Hart"));
Serial.println();
Serial.println(F("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"));
Serial.println(F(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"));
Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void printGPS()
{
pinMode(TxLcdPin, OUTPUT);
digitalWrite(TxLcdPin, HIGH);
mySeriallcd.write(12); //Clears the LCD screen, part of the LCD library for the parallax LCD

mySeriallcd.print("Lat ");mySeriallcd.println(gps.location.lat(),4); //Printing to the LCD
mySeriallcd.write(13); //Moves the cursor to the next line, using just the println caused some randomness with the LCD
mySeriallcd.print("Lon ");mySeriallcd.println(gps.location.lng(),4);
delay(2000);

}

void getTemp() { //The Adafruit datalogging shield came with a temperature sensor, I left it in for this
analogRead(tempPin);
int tempReading = analogRead(tempPin); //Read the analog pin connected to the sensor
float voltage = tempReading * aref_voltage / 1024;
float temperatureC = (voltage - 0.5) * 100 ;
temperatureF = (temperatureC * 9 / 5) + 32;

}

void loop()
{
getTemp(); //Call the getTemp function
String dataString = "";
File dataFile = SD.open("datalog.txt", FILE_WRITE);
//The below prints to the serial monitor for debugging
printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
printInt(gps.location.age(), gps.location.isValid(), 5);
printDateTime(gps.date, gps.time);
printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);
float mylat=gps.location.lat();
float mylon=gps.location.lng();

printGPS();
if (dataFile){ //If the datalogging shield is found, writes to the card.
//This output creates a new placemark for every GPS point taken. This could be done once the data is taken
//off the SD card and plopped on the PC, but I just did it here. The needs to be added to the
//text file before saving as a KML
dataFile.print("");dataFile.print("");dataFile.print(temperatureF);
dataFile.print("");
dataFile.print("");dataFile.print("");
dataFile.print(gps.location.lng(),7);dataFile.print(",");
dataFile.print(gps.location.lat(),7);dataFile.print(",");
dataFile.print(gps.altitude.meters(),7);dataFile.print("");
dataFile.print("");
dataFile.println("");
dataFile.close();
Serial.print(mylat);Serial.print(" mylat ");Serial.println(temperatureF);
}else {
Serial.println("error opening datalog.txt");
}

printInt(gps.charsProcessed(), true, 6);
printInt(gps.sentencesWithFix(), true, 10);
printInt(gps.failedChecksum(), true, 9);
Serial.println();

smartDelay(1000);

if (millis() &gt; 5000 &amp;&amp; gps.charsProcessed() &lt; 10)
Serial.println(F("No GPS data received: check wiring"));
}

// The below functions are not needed if just writing to the datalogger as they're only used in printing to the serial
//monitor
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start &lt; ms); } static void printFloat(float val, bool valid, int len, int prec) { if (!valid) { while (len-- &gt; 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val &lt; 0.0 ? 2 : 1); // . and - flen += vi &gt;= 1000 ? 4 : vi &gt;= 100 ? 3 : vi &gt;= 10 ? 2 : 1;
for (int i=flen; i&lt;len; ++i)
Serial.print(' ');
}
smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
char sz[32] = "*****************";
if (valid)
sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i&lt;len; ++i) sz[i] = ' '; if (len &gt; 0)
sz[len-1] = ' ';
Serial.print(sz);
smartDelay(0);
}

static void printDateTime(TinyGPSDate &amp;d, TinyGPSTime &amp;t)
{
if (!d.isValid())
{
Serial.print(F("********** "));
}
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
Serial.print(sz);
}

if (!t.isValid())
{
Serial.print(F("******** "));
}
else
{
char sz[32];
sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
Serial.print(sz);
}

printInt(d.age(), d.isValid(), 5);
smartDelay(0);
}

static void printStr(const char *str, int len)
{
int slen = strlen(str);
for (int i=0; i&lt;len; ++i)
Serial.print(i smartDelay(0);
}

Getting the parts together for a quadcopter – Transmitter/motors

Turnigy aerodrive motors and a TGY 9X transmitter. All from Hobbyking.com.

The 9X was only $50, only tested once so far but it worked. Will see how it holds up over time since it definitely has the cheap feel to it.

wpid-20140517_121601.jpg

Testing out the Javascript API for ESRI stuff

Just a test page of javascript stuff working through ESRIs ArcGIS online.
http://www.benty.org/Java/java.html

ESRI also has a spiffy sandbox to play around with here :http://developers.arcgis.com/javascript/sandbox/sandbox.html

Code from the book Building Web and Mobile ArcGIS Server Applications with JavaScript at Amazon

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
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
  <title>Create a Map</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">
  <style>
    html, body, #mapDiv {
      padding: 0;
      margin: 0;
      height: 100%;
    }
  </style>
 
  <script src="http://js.arcgis.com/3.9/"></script>
  <script>
  var map;
  require(["esri/map","esri/layers/FeatureLayer","esri/symbols/SimpleFillSymbol","esri/symbols/SimpleLineSymbol","esri/renderers/SimpleRenderer","esri/InfoTemplate","esri/graphic","dojo/on","dojo/_base/Color","dojo/domReady!"],
  function(Map,FeatureLayer,SimpleFillSymbol,SimpleLineSymbol,SimpleRenderer,InfoTemplate,Graphic,on,Color){
     
      map = new Map("mapDiv", {basemap: "streets",
        center: [-96.095,39.726],
        zoom:4,
        sliderStyle: "small"
      });
 
      map.on("load",function() {
        map.graphics.on("mouse-out",
        function(evt) {
          map.graphics.clear();
          map.infoWindow.hide();
         
        });
      });
      var olderStates = new
      FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5",
      {
        mode:FeatureLayer.MODE_SNAPSHOT,
        outFields: ["STATE_NAME","MED_AGE","MED_AGE_M","MED_AGE_F"]
      });
      olderStates.setDefinitionExpression("MED_AGE > 36");
     
      var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
      new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255,255,255,0.35]),1),
      new Color([125,125,125,0.35]));
      olderStates.setRenderer(new SimpleRenderer(symbol));
      map.addLayer(olderStates);
   
      var infoTemplate = new InfoTemplate();
      infoTemplate.setTitle("${STATE_NAME}");
      infoTemplate.setContent("<b>Median Age:</b>${MED_AGE_M}<br/>"
      + "<b>Median Age - Male:</b>${MED_AGE_M}<br/>" +
      "<b>Median Age - Female: </b>${MED_AGE_F}");
      map.infoWindow.resize(245,125);
     
      var highlightSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
      new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([255,0,0]), new Color([125,125,125,0.35])));
     
      olderStates.on("mouse-over",function(evt)
      {
        map.graphics.clear();
       
        evt.graphic.setInfoTemplate(infoTemplate);
        var content = evt.graphic.getContent();
        map.infoWindow.setContent(content);
        var title = evt.graphic.getTitle();
        map.infoWindow.setTitle(title);
        var highlightGraphic = new Graphic(evt.graphic.geometry,highlightSymbol);
        map.graphics.add(highlightGraphic);        
       
        map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
      });
      });
 
  </script>

</head>
<body class="claro">
  <div id="mapDiv"></div>
</body>
</html>

© 2016 Home of Benty

Theme by Anders NorenUp ↑