[Payload] Making a simple payload for a High Altitude Balloon

This post will be about making a simple payload for a high altitude balloon. This involves simple arduino related products, and scraping them together to make a nice rudimentary system. […]

This post will be about making a simple payload for a high altitude balloon. This involves simple arduino related products, and scraping them together to make a nice rudimentary system. The basis for this article and the images are from the backup payload i used for the Space Camera Live 1. You can read all about that project here.

Let's start with a can of colored markers

What you need

Well, you need something to get the position right (GPS), something to send that out (a GSM or Radiotransmitter), and something to handle all of that (Arduino?) and maybe some storage thingy (MicroSD?). Well, arduino can do all of the previous. Arduino’s are pretty reliable, and proven to work for simple things like this. So see below how i stitched some stuff together. A (uncomplete) partslist:
Seeduino Stalker v2 (+microSD built in) (Arduino)
GPS bee (ublox 5 GPS)
Sony Ericsson T68i (GPRS/SMS)

The insides of this (backup) payload

Making a Antenna

I devoted a seperate article on making a good antenna here.

Making a ‘hot wire’ Cutdown Mechanism

I devoted a seperate article to that here.

Controlling a cheap cellphone with Arduino

Got some stuff on that written down here.

Arduino Code

This code just captures from a serial connection with a ublox GPS module, saves to a microSD and makes a cutdown when certain parameters are set. Also, a Sony Ericsson T68i cellphone is attached, that triggers sending of an SMS (PDU) message to my own cellphone including the most recent valid GPS location every 20 seconds after landing. Written down below here was the full final code succesfully used in the Space Camera Live 1 backup payload.

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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
// (c) Space Camera Live 1, 11-09-2011
// Includes snippets from Daniel Richman, James Coxon, Robert Harisson
 
#include "TinyGPS.h"
#include <stdio.h>
#include <util/crc16.h>
#include <Flash.h>
#include <Wire.h>
#include <TMP102.h>
#include <CN3063.h>
#include <SdFat.h> //Eats ~8kb
#include <NewSoftSerial.h>
 
 
#define ENDLN           "\r\n"  // SD
 
/* T68i GPRS */
#define num_to_char(number)   ((number) < 10 ?                           \
                                               ('0' + (number)) :        \
                                               (('A' - 10) + (number)) )
#define first_four(byte)       (0x0F & (byte))
#define  last_four(byte)      ((0xF0 & (byte)) >> 4)
#define hexdump_a(byte)  num_to_char( last_four(byte))
#define hexdump_b(byte)  num_to_char(first_four(byte))
 
NewSoftSerial mySerial(5, 4); //T68I TX Goes in Pin 5
 
TinyGPS gps;
 
int cutdownpin = 9;
 
int count = 0;
byte navmode = 0, maxmode = 0;
float flat=0, flon=0;
unsigned long date, time, chars, age;
 
int hour = 0 , minute = 0 , second = 0, oldsecond = 0;
char latbuf[12] = "0", lonbuf[12] = "0";
long int ialt = 0;
long int maxAlt=0;
int numbersats = 0;
 
int batmv=0;
int temp=0;
 
int descent=0;
unsigned long SmsStart = 0;     // SMS-time
int ExecOnce=0;             // sms checker
 
 
//SD
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
 
// RTTY Functions 
/*
void rtty_txstring (char * string)
{
 
	char c;
	c = *string++;
	while ( c != '\0')
	{
		rtty_txbyte (c);
		c = *string++;
	}
}
 
void rtty_txbyte (char c)
{
 
	int i;
	rtty_txbit (0); // Start bit
	// Send bits for for char LSB first	
	for (i=0;i<7;i++) //7 or 8 bit ascii
	{
		if (c & 1) rtty_txbit(1); 
			else rtty_txbit(0);	
		c = c >> 1;
	}
	rtty_txbit (1); // Stop bit
        rtty_txbit (1); // Stop bit
}
 
void rtty_txbit (int bit)
{
		if (bit)
		{
		  // high
                    digitalWrite(5, HIGH);  
                    digitalWrite(4, LOW);
		}
		else
		{
		  // low
                    digitalWrite(4, HIGH);
                    digitalWrite(5, LOW);
		}
 
                delay(10);
 
                //delayMicroseconds(20500); // 10000 = 100 BAUD 20150
                //delayMicroseconds(20000); // 10000 = 100 BAUD 20150
}*/
 
uint16_t gps_CRC16_checksum (char *string)
{
	size_t i;
	uint16_t crc;
	uint8_t c;
 
	crc = 0xFFFF;
 
	// Calculate checksum ignoring the first two $s
	for (i = 2; i < strlen(string); i++)
	{
		c = string[i];
		crc = _crc_xmodem_update (crc, c);
	}
 
	return crc;
}
 
// Send a byte array of UBX protocol to the GPS
void sendUBX(uint8_t *MSG, uint8_t len) {
  for(int i=0; i<len; i++) {
    Serial.print(MSG[i], BYTE);
  }
  Serial.println();
}
 
// Get the current NAV5 mode
int getUBXNAV5() {
 
	uint8_t b;
	uint8_t byteID = 0;
	int startTime = millis();
 
	// Poll/query message
	uint8_t getNAV5[] = { 0xB5, 0x62, 0x06, 0x24, 0x00, 0x00, 0x2A, 0x84 };
 
	// First few bytes of the poll response
	uint8_t response[] = { 0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF};
 
	// Interrogate Mr GPS...
	sendUBX(getNAV5, sizeof(getNAV5)/sizeof(uint8_t));
 
	// Process his response...
	while (1) {
 
		// Timeout if no valid response in 3 seconds
		if (millis() - startTime > 3000) { 
			return -1;
		}
 
		// Make sure data is available to read
		if (Serial.available()) {
			b = Serial.read();
 
			// 8th byte is the nav mode
			if (byteID == 8) {
				return b;
			} 
			// Make sure the response matches the expected preamble
			else if (b == response[byteID]) { 
				byteID++;
			} else {
				byteID = 0;	// Reset and look again, invalid order
			}
 
		}
	}
 
}
 
 
void setupGPS() {
 
  //Turning off all GPS NMEA strings apart on the uBlox module
  Serial.println("$PUBX,40,GLL,0,0,0,0*5C");
  Serial.println("$PUBX,40,GGA,0,0,0,0*5A");
  Serial.println("$PUBX,40,GSA,0,0,0,0*4E");
  Serial.println("$PUBX,40,RMC,0,0,0,0*47");
  Serial.println("$PUBX,40,GSV,0,0,0,0*59");
  Serial.println("$PUBX,40,VTG,0,0,0,0*5E");
 
  Serial.begin(9600);
 
  delay(3000); // Wait for the GPS to process all the previous commands
 
  // Check and set the navigation mode (Airborne, 1G)   
  uint8_t setNav[] = {0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC};
  sendUBX(setNav, sizeof(setNav)/sizeof(uint8_t));
  navmode = getUBXNAV5();
  //Serial.println(navmode, BIN);
  delay(500);
 
  //set GPS to Maximum performance mode 
  uint8_t setMax[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x01, 0x00, 0x00, 0x19, 0x81};
  sendUBX(setMax, sizeof(setMax)/sizeof(uint8_t));
  maxmode = getUBXNAV5();
  //Serial.println(maxmode, BIN);
  delay(500);
 
}
 
 
// More GPS
 
/*void readgps(){
  Serial.flush();
 
  bool newdata = false;
  unsigned long start = millis();
 
  Serial.println("$PUBX,00*33");
 
  // Check for 1 second
  while (millis() - start < 1000)
  {
    if (feedgps()){
      newdata = true;
    }
  }
  if (newdata)
  {
    //Serial << F("* GPSDATA:") << ENDLN;
    gpsdump(gps);
  }
}
 
void gpsdump(TinyGPS &gps)
{
 
    gps.get_datetime(&date, &time, &age);
    hour = (time / 1000000);
    minute = ((time - (hour * 1000000)) / 10000);
    second = ((time - ((hour * 1000000) + (minute * 10000))));
    second = second / 100;
 
 
 
    numbersats = gps.sats();
 
    if (numbersats >= 1) {
 
      //Get Position
      gps.f_get_position(&flat, &flon);
 
      //convert float to string
      dtostrf(flat, 7, 4, latbuf);
      dtostrf(flon, 7, 4, lonbuf);
 
      //just check that we are putting a space at the front of lonbuf
      if(lonbuf[0] == ' ')
      {
        lonbuf[0] = '+';
      }
 
      // +/- altitude in meters
      ialt = (gps.altitude() / 100);    
    }
 
}
 
bool feedgps()
{
  while (Serial.available()){
    if (gps.encode(Serial.read()))
      return true;
  }
  return false;
}*/
 
 
 
 
// Sensor-stuff
 
int gettemp(){
  int t;
  TMP102.getValues(&t);
  return t;
}
 
int getbat(){
  int bat_volt;
  CN3063.getBatVolt(&bat_volt); //in mV
  return bat_volt;
}
 
/* T68i SMS Code */
 
void hexdump_byte(unsigned char byte)
{
  mySerial.print(hexdump_a(byte), BYTE);
  mySerial.print(hexdump_b(byte), BYTE);
}
 
void send_sms(char *data)
{
  size_t data_length, x;
  char c, l;
  long i;
  long n;
 
  data_length = strlen(data);
  i = data_length * 7;
 
  /* Round i up to a multiple of 8 */
  if (i & 0x07) i = (i & ~0x07) + 0x08;
 
  /* Calculate the number of message octets */
  i = i / 8;
 
  mySerial.println("AT+CMGF=0");
  delay(1500);
  mySerial.print("AT+CMGS=");
  delay(1500);
  mySerial.println(i + 14);
  delay(1500);
  mySerial.print("0011000B911356537837F80000AA");
  hexdump_byte(data_length & 0xFF);
 
  /* from sms_example_v2.c ALIEN Project Daniel Richman */
  l = 0;
  n = 0;
 
  for (x = 0; x < data_length; x++)
  {
    if (data[x] == '$')  data[x] = 0x02;
 
    n |= (data[x] & 0x7F) << l;
    l += 7;
 
    if (l >= 8)
    {
      hexdump_byte(n & 0xFF);
      l -= 8;
      n >>= 8;
    }
  }
 
  if (l != 0)
  {
    hexdump_byte(n & 0xFF);
  }
 
  mySerial.println(0x1A, BYTE);
}
 
 
 
 
 
/*Setup and Main*/
 
 
 
 
 
 
void setup()
{
  pinMode(4, OUTPUT); //Radio Tx0
  pinMode(5, OUTPUT); //Radio Tx1
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(cutdownpin, OUTPUT); 
  //mySerial.println("Hello, world?");
 
  CN3063.attach_ana(7);
  TMP102.init();
  delay(5000); // We have to wait for a bit for the GPS to boot otherwise the commands get missed
 
  setupGPS();
 
    //SD
  if (!card.init()) Serial << F("* SD card init. failed!") << ENDLN;
  if (!volume.init(&card)) Serial << F("* volume init. failed!") << ENDLN;
  if (!root.openRoot(&volume)) Serial << F("* openRoot failed") << ENDLN;
 
  // Check for an available filename
  char fileName[13];
  Serial << F("* Opening log file...") << ENDLN;
  for (int i = 0; i < 1000; i++) {
    sprintf(fileName, "SCLOG%03d.TXT", i);
    if (file.open(&root, fileName, O_CREAT | O_EXCL | O_WRITE)) break;
  }
 
  // Ensure we opened the file without error
  if (!file.isOpen()) {
    Serial << F("* Failed to open log file!") << ENDLN;
  } 
  else {
    file.writeError = false;
    Serial << F("* Logging to ") << fileName << ENDLN;
    file.write("* ");
    file << F("Project SpaceCameraLive booted!") << ENDLN;
    if (file.writeError || !file.sync()){ 
      Serial << F("* Error writing to SD card!") << ENDLN;
    }/* else {
      send_sms("SD Works!"); 
    }*/
  }
  Serial << ENDLN;
 
 
}
 
 
/* Main Loop */
 
 
 
void loop() { 
    char superbuffer [120];
    char checksum [10];
    int n;
 
    temp=gettemp();
    batmv=getbat();
 
    Serial.println("$PUBX,00*33"); //Poll GPS
 
    while (Serial.available())
    {
      int c = Serial.read();
      if (gps.encode(c))
      {
        //Get Data from GPS library
        //Get Time and split it
        gps.get_datetime(&date, &time, &age);
        hour = (time / 1000000);
        minute = ((time - (hour * 1000000)) / 10000);
        second = ((time - ((hour * 1000000) + (minute * 10000))));
        second = second / 100;
      }
    }
 
    numbersats = gps.sats();
 
    if (numbersats >= 1) {
 
      //Get Position
      gps.f_get_position(&flat, &flon);
 
      //convert float to string
      dtostrf(flat, 7, 4, latbuf);
      dtostrf(flon, 7, 4, lonbuf);
 
      //just check that we are putting a space at the front of lonbuf
      if(lonbuf[0] == ' ')
      {
        lonbuf[0] = '+';
      }
 
      // +/- altitude in meters
      ialt = (gps.altitude() / 100);    
    }
 
    n=sprintf (superbuffer, "$$PD4TA,%d,%02d:%02d:%02d,%s,%s,%ld,%d,%d,%d", count, hour, minute, second, latbuf, lonbuf, ialt, numbersats, temp, batmv);
    if (n > -1){
      n = sprintf (superbuffer, "%s*%04X\n", superbuffer, gps_CRC16_checksum(superbuffer));
      //noInterrupts(); //DO NOT USE (No)Interrupts!
      //rtty_txstring(superbuffer); //Not using RTTY on this launch in this module
      //interrupts(); //DO NOT USE (No)Interrupts!
 
    }
 
    /* SMS send parameters */
    /* After 15 strings.. */
    if( count == 15){
      send_sms(superbuffer);
    }
 
    // Keep track of the maximum altitude
    if (ialt > maxAlt) { 
      maxAlt = ialt; 
    }
    // Check to see if we've fallen 1000m, if so switch to descent mode
    if (ialt < (maxAlt - 1000)) { 
      descent = 1; 
    } 
 
    /* When it has dropped below 900m */
    if (descent == 1){
      if (ialt < 900){
 
        if (ExecOnce == 0){
          SmsStart = millis();
          ExecOnce = 1;
          send_sms(superbuffer);
          file << "SMS verstuurd" << ENDLN;
          delay(50);
        }
        if (millis() - SmsStart > 20000){
          ExecOnce =0;
        }
 
      } 
    }
 
    /* Cutdown Paramters 
    (1,2) If its to the north OR east of Urk
    (3) OR if it is in descent mode
 
    */
    if( flon > 5.6 || flat > 52.7 || descent == 1 )
    {
      Serial.println("Cutdown params met");
      digitalWrite(cutdownpin, HIGH);
      delay(5000);
      digitalWrite(cutdownpin, LOW);
      delay(2000);
      digitalWrite(cutdownpin, HIGH);
      delay(10000);
      digitalWrite(cutdownpin, LOW);
      delay(2000);
      digitalWrite(cutdownpin, HIGH);
      delay(5000);
      digitalWrite(cutdownpin, LOW);
    } /*else {
      Serial.println("Cutdown params not met");
    }
 
      Serial.println(flat);
      Serial.println(flon);
      Serial.println(ialt);
      Serial.println(maxAlt);
      Serial.println(descent);
      Serial.println(ExecOnce);
      Serial.println();
    */
    count++;
 
    //Serial << superbuffer << ENDLN;
    file << superbuffer << ENDLN;
    file.sync(); //Force update SD
    delay(1000); //give some rest
    delay(2500); //Extra rest
}

About Tim Zaman

There's page about myself with some babble and pics on this site Here!. // R&D : Vision/Imaging | 2D/3D Image Processing | Robotics/Automation | Programming | Electronics | Open Source | And, obviously, Photography.

Creative Commons License
[Payload] Making a simple payload for a High Altitude Balloon by Tim Zaman, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 3.0 Unported License.