Show Posts
Pages: [1] 2 3 ... 8
1  Using Arduino / Programming Questions / Re: trouble with programming a calibration routine on: March 13, 2013, 02:55:12 pm
I think I have it running properly now

 
Code:
#include <Wire.h>
 #include <NewSoftSerial.h>
char c = 'c';
char e = 'e';
void setup()
{
  
  Serial.begin (9600);
  Serial.println("Welcome To The HMC6352 Calibration Routine! ");
  Serial.println("");
  Serial.println("Press lower case  'c' To Begin Calibration Routine");
  Serial.println("Press lower case 'e' To End Calibration Routine");
 

}

void loop()
{

 Wire.beginTransmission(0x21);

while (Serial.available() == 0)
{

  char b = Serial.read();
  if (c == b){
    Wire.send("C");
  Serial.println("Beginning Routine");
  Serial.println("C");
  }
   if (e == b)
  {
    Serial.println("check");
    Wire.send("E");
    Serial.println("Ending Calibration Routine");
  }
  
}


thanks everyone!
2  Using Arduino / Programming Questions / Re: trouble with programming a calibration routine on: March 13, 2013, 01:42:42 pm
@awol, the conversion was in there, and it used the correct values

@mark and afremont.

I rewrote the code to make it more straightforward looking, but it is the same piece of code. When I type anything other than "c". This is the output, the code is below that.

Code:
Welcome To The HMC6352 Calibration Routine!

Press lower case  'c' To Begin Calibration Routine
Press lower case 'e' To End Calibration Routine
c
Beginning Routine
C
e
Beginning Routine
C
f
Beginning Routine
C

Code:
#include <Wire.h>
char c = 'c';
char e = 'e';
void setup()
{
  Serial.begin (9600);
  Serial.println("Welcome To The HMC6352 Calibration Routine! ");
  Serial.println("");
  Serial.println("Press lower case  'c' To Begin Calibration Routine");
  Serial.println("Press lower case 'e' To End Calibration Routine");
 

}

void loop()
{

 Wire.beginTransmission(0x21);

while (Serial.available() == 0);
  char b = Serial.read();
  Serial.println(b);
  if (b =c){
    Wire.send("C");
  Serial.println("Beginning Routine");
  Serial.println("C");
  }
   if (e == Serial.read())
  {
    Serial.println("check");
    Wire.send("E");
    Serial.println("Ending Calibration Routine");
  }
 
  else if(b!=c && b!=e)
   
    Serial.println("please enter only 'c' or 'e'");
 
}
3  Using Arduino / Programming Questions / trouble with programming a calibration routine on: March 13, 2013, 12:09:19 pm
Hi,

I'm attempting to write a calibration routine for a digital compass. the compass enters calibration mode when it receives a message "c" and exits calibration mode when it receives "e".

The code is below.

The issue I am having is that I get the appropriate message when entering "c", but I only get a value of "101" when I enter "e". I don't understand why it isn't entering the if statement assigned to that reading. Can someone possibly help me understand what is going on here? Any help or advice is much appreciated!

below is the output after entering "c" then "e"

Code:
Welcome To The HMC6352 Calibration Routine!

Press lower case  'c' To Begin Calibration Routine
Press lower case 'e' To End Calibration Routine
99
Beginning Routine
C
101

Code:
#include <Wire.h>

void setup()
{
  Serial.begin (9600);
  Serial.println("Welcome To The HMC6352 Calibration Routine! ");
  Serial.println("");
  Serial.println("Press lower case  'c' To Begin Calibration Routine");
  Serial.println("Press lower case 'e' To End Calibration Routine");
 

}

void loop()
{

 Wire.beginTransmission(0x21);

while (Serial.available() == 0);
  int val = Serial.read();
  Serial.println(val);
  if (val == 99){
    Wire.send("C");
  Serial.println("Beginning Routine");
  Serial.println("C");
  }
   if (101 == Serial.read())
  {
    Serial.println("check");
    Wire.send("E");
    Serial.println("Ending Calibration Routine");
  }
 
  else if(val!=99 && val!=101)
   
    Serial.println("please enter only 'c' or 'e'");
 
}
4  Using Arduino / Sensors / wrong values on HMC6352 on: February 26, 2013, 05:09:36 pm
Hi,
I have recently been performing some experiments interfacing HMC6352 breakouts to an arduino uno

https://www.sparkfun.com/products/7915

https://dlnmh9ip6v2uc.cloudfront.net/images/products/1/1/0/2/1/11021-01a.jpg

in my experiments, I have taken each compass breakout, and wired it to an arduino uno 1 foot away. This is to make sure they are unaffected by any metal on the board, or the power source on the board. The arduinos are secured to the board with zip ties, and the compasses are secured with foam tape. I have taken the compasses outside, and taken readings every 4 seconds, in between which I rotate the setup 90 degrees. Most of the modules rotate the same number of degrees, however, a few of the modules seem to have compounded decreased readings up to 270 degrees (360 degrees by the other compasses) when rotated to the 90 degree point, the compasses seem to be accurate again. Some of the compasses seem to have compressed reading differences around what should read as 180-360 degrees.

I am trying to figure out why this is. Does anyone have any suggestions on what it might be? Or where to begin looking for what might be causing this?

any help is much appreciated. Thanks!
5  Using Arduino / Networking, Protocols, and Devices / Re: I2C and SD issue on: February 11, 2013, 06:40:18 pm
ok, I get the syntax for dtostrf() now. Thanks for your help! Here's the finished code. Feel free to critique it further if you like, but everything seems to be working great now

Code:
#include <NewSoftSerial.h>
#include <Wire.h>
#include <SD.h>

const int CS=8;
int HMC6352 =0x42;
int slave;
byte headingData[2];
int i,headingValue;
long id = 1;
#include <Time.h>
#include <TimeAlarms.h>
#include <TextFinder.h>
NewSoftSerial gps(3,4);
TextFinder finder(gps);
const int NUMBER_OF_FIELDS = 8;
int values[NUMBER_OF_FIELDS];
void setup()
{
  slave =HMC6352>>1;
  Serial.begin(9600);
  gps.begin(9600);
  Serial.println("bloop");
  Alarm.timerRepeat(10, RepeatTask);
  Wire.begin();
  pinMode(8,OUTPUT);
  if (!SD.begin(CS)) {
    Serial.println("Card failed, or not present");
    return;
  }
}
void RepeatTask()
{

  Serial.println(millis());
  Serial.println("");

  char mychar[7];
  char com[]=",";
  char buff[100];
  int length=100;
  finder.find("$GPGGA,");
  finder.getString( "$GPGGA,", "\r\n", buff, length);

  strcat(buff,com);

  Wire.beginTransmission(0x21);
  Wire.send("A");     
  delay(100);         
  Wire.requestFrom(0x21, 2);
  byte MSB = Wire.receive();
  byte LSB = Wire.receive();
  Wire.endTransmission();
  float myres = ((MSB << 8) + LSB) / 10;
  delay(100);
  dtostrf(myres,6,2,mychar);
  strcat (buff,mychar);
  File datafile = SD.open("datalog.txt",FILE_WRITE);
  if (datafile) {
    datafile.print(buff);

    datafile.close();
    Serial.println(buff);
  }

}

void loop()
{
  Alarm.delay(1000);
}
6  Using Arduino / Networking, Protocols, and Devices / Re: I2C and SD issue on: February 11, 2013, 03:54:35 pm
PaulS,

trying dtostrf() for some reason is hiding all of my output except for the compass measurement.

the rest of the code is the same, I've only replaced the sprintf with this

Code:
dtostrf(headingInt,100,2,buff);

the output is this

Code:
bloop
10001

                                                                                                0.00
0.00

any idea what is going on here? I've tried various sizes to make "buff" but the output is always the same
7  Using Arduino / Networking, Protocols, and Devices / Re: I2C and SD issue on: February 11, 2013, 02:08:43 pm
PaulS

sorry for the slopiness, that was part of something I was trying the other day, I forgot to remove the assignments. I've since cleaned it up and modified the post
8  Using Arduino / Networking, Protocols, and Devices / Re: I2C and SD issue on: February 11, 2013, 02:03:59 pm
I found some careless errors, so the code and output has been changed. The only issue I am now having is with printing the compass value, as you can see it only prints "?" where I attempted to append the value to the string "buff"
9  Using Arduino / Networking, Protocols, and Devices / I2C and SD issue on: February 11, 2013, 01:10:09 pm
Code:
Hi,

I was wondering if anyone could see a problem with my technique or with my code that explains why my output isn't printing to my SD card (no file is created), and why my compass output is not printing to my serial monitor. I've used these bits of code before and have not had any issues. I've also verified that all of the peripherals are working properly, and are properly connected

below is the code,

[code\]
#include <NewSoftSerial.h>
#include <Wire.h>
#include <SD.h>
const int CS=8;
int HMC6352slave =0x42;
int HMC6352read = 0x41;
int heading;
long id = 1;
#include <Time.h>
#include <TimeAlarms.h>
#include <TextFinder.h>
NewSoftSerial gps(3,4);
TextFinder finder(gps);
const int NUMBER_OF_FIELDS = 8;
int values[NUMBER_OF_FIELDS];
void setup()
{
  Serial.begin(9600);
  gps.begin(9600);
  Serial.println("bloop");
  Alarm.timerRepeat(10, RepeatTask);
  Wire.begin();
  pinMode(8,OUTPUT);
  if (!SD.begin(CS)) {
    Serial.println("Card failed, or not present");
    return;
}
}
void RepeatTask()
{
 
  Serial.println(millis());
  Serial.println("");
 
  char mycharpointer[7];
  char com[]=",";
  char buff[90];
  int length=90;
  finder.find("$GPGGA,");
  finder.getString( "$GPGGA,", "\r\n", buff, length);


Wire.beginTransmission(HMC6352slave);
Wire.send(HMC6352read);
Wire.endTransmission();
delay(10);
Wire.requestFrom(HMC6352slave, 2);
byte MSB = Wire.receive();
byte LSB = Wire.receive();
float headingSum = (MSB<<8) + LSB;
float headingInt = headingSum/10;
sprintf(mycharpointer,"%f",headingInt);
strcat(buff,com);
strcat(buff,mycharpointer);
Serial.println(buff);
Serial.println(headingInt);
File datafile = SD.open("datalog.txt",FILE_WRITE);
 if (datafile) {
   datafile.println(buff);
   datafile.close();

  }
 
}

void loop()
{
  Alarm.delay(1000);
}


below is what I get on the serial monitor. All of it prints, except for the last value, which, since I've tested, should be around 78.9

Code:
bloop
240001

190106.000,bleeh.9037,N,blahhh.0006,W,2,7,1.30,161.5,M,-33.3,M,0000,0000*62,?
0.00


any advice or insights are much appreciated!
10  Using Arduino / Programming Questions / Re: concatenating arrays in with textfinder on: February 07, 2013, 07:40:19 pm
Specifically I've been attempting to concatenate them by each index.
11  Using Arduino / Programming Questions / concatenating arrays in with textfinder on: February 07, 2013, 07:38:27 pm
I've been struggling to figure out, is it possible to concatenate the value array for each field using the textfinder library?

here is the example code

Code:
/*
 * SerialReceiveMultipleFields with textFinder
 * This code expects a message in the format: H 12,-345,678!
 */

#include <TextFinder.h>
#include <NewSoftSerial.h>

NewSoftSerial pps (3,4);
TextFinder  finder(pps); 
const int NUMBER_OF_FIELDS = 8; // how many comma seperated fields we expect                                           
int values[NUMBER_OF_FIELDS];   // array holding values for all the fields

void setup()
{
  Serial.begin(9600); // Initialize serial port to send and receive at 9600 baud
pps.begin(9600);
}

void loop()
{
  int fieldIndex = 0;            // the current field being received
  finder.find("H");   
  while(fieldIndex < NUMBER_OF_FIELDS)
    values[fieldIndex++] = finder.getValue();     
  Serial.println("All fields received:");

  for(fieldIndex=0; fieldIndex < NUMBER_OF_FIELDS; fieldIndex++)
  {
  Serial.println(values[fieldIndex]);
   
}
}

12  Using Arduino / Programming Questions / Re: timer printing and array of serial data issue on: February 06, 2013, 04:50:06 pm
Paul,

I am looking for something that doesn't rely on how long it takes to shift out the data. I realize that it does take time to shift out the data. i'm only looking to print every 10 seconds. That being said, it needs to be uncoupled from the the looping times, because (in my case) the looping times will vary

13  Using Arduino / Programming Questions / Re: timer printing and array of serial data issue on: February 06, 2013, 04:00:09 pm
I ask b/c it would seem that it isn't possible to use interrupts to time outputs from the micro-controller. Here is an example from the library. Does it only work because any analog values are going to be lower than the 64 byte serial buffer?

Code:
    #include "Timer.h"
     
     
    Timer t;
    int pin = 13;
     
     
    void setup()
    {
      Serial.begin(9600);
      pinMode(pin, OUTPUT);
      t.oscillate(pin, 100, LOW);
      t.every(1000, takeReading);
    }
     
     
    void loop()
    {
      t.update();
    }
     
     
    void takeReading()
    {
      Serial.println(analogRead(0));
    }
14  Using Arduino / Programming Questions / Re: timer printing and array of serial data issue on: February 06, 2013, 03:51:08 pm
Do you have any recommendations or direction for methods I might pursue to do what I am attempting?
15  Using Arduino / Programming Questions / timer printing and array of serial data issue on: February 06, 2013, 02:37:09 pm

   

I was wondering if you guys could help me solve an arduino Coding problem. I've simplified the code to highlight the issue that I'm having. I've created a program to read streaming serial data to an array. This array needs to be printed at a specific time interval, delays in this case are insufficient, and I have resorted to using timer.h which can be found here http://playground.arduino.cc/Code/Timer . My intention was to read to an array of size index, and increment index. When index becomes a value of 80, it is supposed to save the the array (inData) to another array("prntfd"). ("prntfd") is printed every 5 seconds. In this I hoped to decouple the serial timing, and the print timing of a serial data array.

Unfortunately the code only prints "c", and a print line. The code is below. Any insights would be much appreciated

Code:
//Sketch feeds serial data to array (inData) of size (index).
//A timer library is then used to print the data every 5 seconds
//debugs: a,b,c are inserted at various parts of the code.
//Serial data from inChar should print every 5 seconds just after C.


//Include timer libraries and serial library
#include <Event.h>
#include <Timer.h>
#include <NewSoftSerial.h>

//set serial pins, serial feed array "inData" and its index "index"
NewSoftSerial nss(3,4);
Timer t;
char inData[80];
static char prntfd[80];
int index = 0;

void setup()
{
  Serial.begin(9600);
  nss.begin(9600);
  t.every(5000, takeReading);//set call time to function "take reading"
}

void loop()
{

  t.update();
 
  char inChar = nss.read();
  if (index <(80))
  {
    inData[index++] = inChar;
    inData[index] = '\0';
  }
  else if (index == 80)
  inData == prntfd;
  index = 0;
}
void takeReading()
{
  Serial.println("c");
  Serial.println(prntfd);

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