Arduino Micro + OpenLog difficulties

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
dskrainka
 
Posts: 9
Joined: Tue Feb 04, 2014 12:22 am

Re: Arduino Micro + OpenLog difficulties

Post by dskrainka »

Here's the code. I'm having trouble posting the ASCII 'junk' from the textfile on the SD card, it seems to mess with the posting mechanism on adafruit's site

Code: Select all

//Analog pins
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;

//The minimum and maximum values that came from
//the accelerometer
int minVal = 265;
int maxVal = 402;

double x;
double y;
double z;
double x1;
double y1;
double z1;

int val = 0;         // variable to store the read value

void setup(){
  Serial1.begin(9600); 


}

void loop(){

  x = analogRead(xPin);
  y = analogRead(yPin);
  z = analogRead(zPin);

  int xAng = map(x, minVal, maxVal, -90, 90);
  int yAng = map(y, minVal, maxVal, -90, 90);
  int zAng = map(z, minVal, maxVal, -90, 90);

  x1 = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
  y1 = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
  z1 = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);

  double x2 = ((x-333)/77);
  double y2 = ((y-333)/77);
  double z2 = ((z-333)/77);

  double root = ((x*x) + (y*y) + (z*z)); 
  double mag = sqrt(root);
 



  int mag7 = (mag / 7);

  Serial1.write(mag7);

  delay(3.57);//Sampling Rate Selection (this is ~280 Hz)

}



User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Micro + OpenLog difficulties

Post by adafruit_support_bill »

What are you expecting to see in your files? What you are writing is binary data, not text.

Code: Select all

int mag7 = (mag / 7);

  Serial1.write(mag7);
If you want ASCII text, you should use "print()", not "write()".
http://arduino.cc/en/Reference/Software ... xhRpPldV8E
http://arduino.cc/en/Reference/Software ... xhRJPldV8E

dskrainka
 
Posts: 9
Joined: Tue Feb 04, 2014 12:22 am

Re: Arduino Micro + OpenLog difficulties

Post by dskrainka »

I'm expecting numbers in my text files. Usually something like:

468
409
357
60
40
etc.

If I use print(), won't that just go to the serial monitor? write() was working for me on the Uno.

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Micro + OpenLog difficulties

Post by adafruit_support_bill »

If I use print(), won't that just go to the serial monitor?
Only if you do Serial.print(). If you call Serial1.print(), it will go to your software serial port.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”