Show Posts
Pages: 1 [2] 3 4 ... 8
16  Forum 2005-2010 (read only) / Syntax & Programs / Re: CRC byte assembly and disassembly on: January 17, 2011, 04:30:58 pm
Thanks a lot
17  Forum 2005-2010 (read only) / Syntax & Programs / CRC byte assembly and disassembly on: January 17, 2011, 08:43:45 am

I have a stream of bytes with a final crc byte I would like to compare with to check for errors.

in visual basic, it is written like this:
For i=o To (n_rx - 2)
  crc += rxbuf(i)
Next i
crc = crc And HFF
If crc = rxbuf(n_rx -1)Then

How would I translate this to arduinian?
18  Forum 2005-2010 (read only) / Syntax & Programs / Re: A time to log how long an event goes for on: December 22, 2010, 08:37:04 am
Check the pulseIn() function
19  Forum 2005-2010 (read only) / Syntax & Programs / Re: help choping up a string on: March 18, 2010, 03:56:16 pm

20  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arrays in classes on: February 20, 2010, 02:06:08 pm
If you have three values, shouldn't you have 4 places? have you tried int _morseCode[4] = {1,2,3}; ?

21  Forum 2005-2010 (read only) / Syntax & Programs / Re: Sketch returning to setup() on: June 19, 2009, 01:46:54 pm
Thanks guys (?),

It seems like RAM was indeed the reason for the setup "loop". I halved the buffer and now the problems lie elsewhere.

Thanks again

22  Forum 2005-2010 (read only) / Syntax & Programs / Re: Sketch returning to setup() on: June 19, 2009, 10:59:13 am

It's a 328, can the ram usage be the problem?

23  Forum 2005-2010 (read only) / Syntax & Programs / Sketch returning to setup() on: June 19, 2009, 09:57:32 am

I have written a sketch that I would like to debug and get to work. But I have encountered a strange problem. The setup() runs once like it's supposed to, and the loop() starts, but then we are back to setup() again.

The setup is so far only an lcd screen on serial (d7), but eventually we will read serial from d0 and process gps data. Can the board reset due to a disturbance from something in the code?

here's an extract:
/*Fore! A program created by Joachim Bakke with the help of the Arduino forum and many programs with functionalities included here.
* Based on a csv file on an SD card, positions for the tees and greens are loaded.
* Current time, position and altitude is collected from strings of NMEA from a GPS connected to the arduino
* Distance to green (middle), last shot distance (and which club) is calculated and displayed.
* The shot lengths are recorded to the SD card for statistical analysis.

*Serial input from NMEA is on d4
*Serial output for NMEA is on d6
*Potmeter on d5
*Mark button is on d2 (interrupt 0)
*Next hole button on d3 (interrupt 1)
*SD card powered from d8?? Check if necessary, can be powered directly
*LCD screen on pin d7

#include <SoftwareSerial.h>  //For connecting the display to any digital pin
#include <SparkFun_SerLCD.h> //for the display
#include <EEPROM.h>          //for writing brightness value to EEPROM
#include <string.h>          //These two are for Checksum calculatino for the NMEA output
#include <ctype.h>
#include <avr/pgmspace.h>
#include <Flash.h>           //In order to use table for tee and green positions for each hole
#include <microfat2.h>        //These three are for writing to and reading from an SD card
#include <mmc.h>             //
#include <SDuFAT.h>          //
#include <wprogram.h>
#include "SDWriter.h"

//#define rxPin 4             //NMEA input pin for distance and RTC (SoftwareSerial)
//#define txPin 3             //not in use currently
#define ledPin 13
//SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
byte pinState = 0;

int byteNMEA=-1;                  // a byte of the NMEA stream cominig in on serial port
 char linea[300] = "";             // a string buffer that we write each byteNMEA to
int count=0;
 int check1 = 0;          //check for gga sentence
 int check2 = 0;          //check for rmc sentence
 int counta=0;
 int index[10];
 char HdrStr1[5] = "GGA";            // the header of the sentence we are trying to find to convert
 char HdrStr2[5] = "RMC";              // This nmea string includes tha date, which we need
 char Str1[10] = "";
 char Str2[10] = "";
 char Str3[10] = "";
 char Str4[10] = "";
 char Str5[10] = "";
 char Str6[10] = "";
// char Str7[10] = "";    
 //char Str8[10] = "";
 char Str9[10] = "";
 char Str10[10] = "";    //We use this for date

int FullDate = 0;
int FullTime = 0;    
int TimeZone = 2;    //UTC + 1 and daylight savings time
double RawLat = 0;
double RawLong = 0;
boolean ValidFix = false;

double TeeLat = 0;      //positions are stored as DDMM.mmm
double TeeLong = 0;
int TeeAlt = 0;
double LastPosLat = 0;  //For example on a par 5, it can be used to measure transport shots
double LastPosLong = 0;
int LastAlt = 0;
double CurrentPosLat = 5910.300;
double CurrentPosLong = 1050.100;
int CurrentAltitude = 0;
double GreenLat = 0;
double GreenLong = 0;
int GreenAlt = 0;
int dist = 0;

int CurrentHole = 0;
int ClubVicinity = 10000 ;    //Threshold for being in the vicinity of the golf course
int TeeVicinity = 20;         //Threshold for being close enough to the next tee to change hole

int potpin = 5;    // potmeter pin to dim lcd backlight
int potvalue;             // variable to keep the actual potmeter value
int club = 0;

int MarkButtonState = 0;        //Variable to show if the "mark" button has been pressed
int ShotCount = 0;              
int NextButtonState = 0;        //Variable to show if the "next" button has been pressed

int StatButton = 0;            //Rocker switch for statistics/measurements
int statState = 0;

prog_char club_0[] PROGMEM = "Dr";
prog_char club_1[] PROGMEM = "3W";
prog_char club_2[] PROGMEM = "Hyb";
prog_char club_3[] PROGMEM = "3I";
prog_char club_4[] PROGMEM = "4I";
prog_char club_5[] PROGMEM = "5I";
prog_char club_6[] PROGMEM = "6I";
prog_char club_7[] PROGMEM = "7I";
prog_char club_8[] PROGMEM = "8I";
prog_char club_9[] PROGMEM = "9I";
prog_char club_10[] PROGMEM = "PW";
prog_char club_11[] PROGMEM = "GW";
prog_char club_12[] PROGMEM = "LW";
prog_char club_13[] PROGMEM = "N/A";
prog_char club_14[] PROGMEM = "N/A";

PROGMEM const char *string_table [] =
  club_14 };
char ClubSelection[30];  

//int bright = 0;              // Brightness of LCD Screen in %
int value = 0;               // Temporary variable for EEPROM

sf_LCD lcd = sf_LCD(7);       // desired LCD pin

//int addr = 0;   // The address to read/write in EEPROM (if needed)

FLASH_TABLE(double, hole_table, 6,    //Tee latitude,Tee longitude,Tee elevation,Green latitude,Green longitude,green elevation
{5922.119,1040.898,20,0,0,0},                   //"HOLE 0" is the club house        

SDWriter sd; // create an SDWriter

void setup()

 Serial.begin(4800); //in SD exapmple, the rate is 19200
 Serial.println("Start of Setup");
 //pinMode(rxPin, INPUT);    //NMEA input
 //pinMode(txPin, OUTPUT);
// attachInterrupt(0, mark, RISING);    //meaning the function mark() will be run once the mark button is pressed (d2)
// attachInterrupt(1, next, RISING);    //d3 button will change to next hole
 pinMode(potpin, INPUT);    //Potmeter is input
 //pinMode(MarkButton, INPUT);//re-written as interrupt
 //sd.init(PSTR("EVJESTAT CSV")); //open file evjestat.csv, 20KB should be plenty for this
 if(StatButton == HIGH){    //if the rocker is set to Statistics, move to loop
for (int i=0;i<300;i++){       // Initialize a buffer for received data
     linea[i]=' ';

  lcd.brightness(80);,1,"Joachim Bakke 09");,1,"   Fore! v0.2   ");

void loop()
  boolean ValidFix = false;//for testing
   if (ValidFix == false){
    lcd.empty();,1,"Joachim Bakke 09");,1,"Fore! v0.2 NoGPS");
  lcd.empty();,1,"Joachim Bakke 09");
  int UtcHour = FullTime / 10000;    //no need for seconds
  int minute = (FullTime - UtcHour)/100;
  int hour = UtcHour + TimeZone;,1,"Fore! v0.2 ");
  if (hour<=9){
   if (minute<=9){

if (FullDate== 0){    //Only need to run this once every time the arduino is powered, in order to get the date.
  FullDate = GetNMEADate();}
GetNMEA();    //Must search for close tee as long as the loop is run, in order to enter loop once it is near a tee.
 int distToClubHouse = 200;
  while (/*int*/ distToClubHouse /*= distancePyth(CurrentPosLat,hole_table[0][0],CurrentPosLong,hole_table[0][1])*/ <= ClubVicinity) {
   //Will kick out of the loop if not even close to club house
    for (int i= 1; i >= 18; i++){
      if (int dist = distancePyth(CurrentPosLat,hole_table[i][0],CurrentPosLong,hole_table[i][1]) >= TeeVicinity) {  
        CurrentHole = i; //

no more space to put code, sorry for the mess...

Best regards,
24  Forum 2005-2010 (read only) / Interfacing / Anyone made an oscilloscope from touchshield? on: May 24, 2009, 09:37:20 am
I have seen a couple of oscilloscopes on processing, but how about making a portable one without the need for a computer? I cannot find too many examples out here on the touchshield, is it easy to "translate" from processing to it?

25  Forum 2005-2010 (read only) / Development / Re: NewSoftWareSerial causes restart on: July 17, 2009, 02:19:22 am
Thanks again Mikal,

Deleting the o file did the trick. Why didn't I think of that?

Anyway, enjoy the summer!

26  Forum 2005-2010 (read only) / Development / Re: NewSoftWareSerial causes restart on: July 16, 2009, 02:06:29 pm
Here is the relevant code. If you try it, you will (probably) see that once nmea is called to print the string, the board resets.

I've said it before, but I'm a big fan of your work, Mikal!

#include <NewSoftSerial.h>

NewSoftSerial NMEA(255,9);     //rx,tx

void setup()

 NMEA.begin(4800); //Opens NewSoftSerial port to send NMEA data through pin 9

void loop()
  char CSSentence[] = "123";
  int CS = 79;
Serial.println(CS, HEX);
NMEA.println(CS, HEX);

27  Forum 2005-2010 (read only) / Development / Re: NewSoftWareSerial causes restart on: July 16, 2009, 01:55:34 pm

I know. However I have tried (9,9) and other combinations before, but not 255... Anyhow, that did not solve the problem. It doesn't seem logical to me. the string is printed well to the LCD, which is called as such:
sf_LCD::sf_LCD ( int pin )

      : NewSoftSerial(pin,pin) {                                
      _w=2; _p=pin;                                              

I assume that is the same as writing (9,9) in my case.

the nmea object can write a bracketed text string, but fails to write a predefined string. This string can however be printed to serial and lcd...

I'm lost!
28  Forum 2005-2010 (read only) / Development / Re: NewSoftSerial causes restart on: July 13, 2009, 01:55:09 pm
..of course it is called NewSoftSerial.

I have discovered that when I try to print a string to NMEA, the 2009 restarts. As print is inherited and not an integral part of NewSoftSerial, I'm puzzled. And on top of all that, I can write the string to lcd, which is also a NewSoftSerial object...

29  Forum 2005-2010 (read only) / Development / NewSoftWareSerial causes restart on: July 13, 2009, 07:26:48 am
Hi all,

I have been programming and soldering for a while on a digital compass for my boat. When I added a serial chip and an instance called NMEA to the program, it crashes every time I write a sentence to the NMEA port. I have been using hardware serial upto now, and it writes my nmea sentences beautifully, but the same sentence causes a crash in NMEA. Any idea what might cause this?

#include <Wire.h>            //For the compass
#include <NewSoftSerial.h>
#include <SparkFun_SerLCD.h> //for the display
#include <EEPROM.h>          //for writing brightness value to EEPROM
#include <string.h>          //These two are for Checksum calculatino for the NMEA output
#include <ctype.h>

sf_LCD lcd = sf_LCD(7);       // desired LCD pin
NewSoftSerial NMEA(0,9);     //rx,tx

void setup()
 value =;
 bright = value;  

 NMEA.begin(4800); //Opens NewSoftSerial port to send NMEA data through pin 9

void loop()
Serial.println(CS, HEX);

NMEA.println(CS, HEX);

Now the Serial.print works well, but once I expose NMEA.print, it crashes and restarts void setup().
The rest of the code is not really that important. It's a 2009 with 168 chip, and the code is abt 13K. I don't think RAM is the issue. Any suggestions?

30  Forum 2005-2010 (read only) / Development / Re: SparkFun Seial LCD with NewSoftSerial on: June 24, 2009, 06:54:49 am
Hi Mikal,

You were right, I fiddled with it, and then discovered I was using the two in a lovely mix. Got it working now, and with your TinyGPS it makes a lovely combination!!

Pages: 1 [2] 3 4 ... 8