Go Down

Topic: Lilypad accelerometer returning weird symbols (Read 799 times) previous topic - next topic

Hi!

I've just been testing a Lilypad MainBoard + ftdi basic breackout, connected through a simple conductive thread to a lilypad accelerometer, and the code:

int sensorValue;
int accelero = 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  sensorValue = analogRead(accelero);
  Serial.println(sensorValue);
  delay(500);
}

And I keep having these symbols printed on the Serial Monitor instead as the analog read numbers:

æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ?????æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???æ???ææ????þæ???þþæ????þæ???þ`óÀ??à`óÀ???þæ???æ~óÀ??üæ???æ`óÀ???þæ???æ~óÀ??x

I know this is probably a very newbie question, but can someone please help me?

Thanks a lot!

wildbill

Make sure the serial monitor is set to 9600 baud too

MarkT

And make sure the board setting is right when you upload to the Lilypad, its an 8MHz clock...
[ I won't respond to messages, use the forum please ]

vrgomes

I had also that on a serial connection. That problem was that i didn't connected the GROUND cable to arduino.

Thanks everyone for all the replies!

It ended up being a much dummer problem. I just needed to set Arduino software to Lilypad (it was to Duemilanove).
Also, I've altered the example with accelerometers that comes within Arduino's default examples.
I've mixed it with this code by Chris from Robot is Happy (http://www.robotishappy.com/2010/08/part-1-visualizing-3-axis-accelerometer-readings-in-processing/), and I was able to communicate and test my Lilypad connected to a simple 3-axis accelerometer with the following code:

import processing.serial.*;
import processing.opengl.*;
Serial myPort;
int baudRate = 9600;
int lf = 10;

PFont font;
int[] xAxis;
int[] yAxis;
int[] zAxis;

int currentX = 0;
int currentY = 0;
int currentZ = 0;
//these value were determined by taking readings from a resting position
int oneGSensorValue = 400;
float oneGMillivolt = oneGSensorValue * 4.9;

int totalReadings = 800;
int readingPos = 0; // the reading position in the array

void setup(){
  smooth();
  size(800, 500, OPENGL);

  font = createFont(PFont.list()[270], 24);
  smallFont();

  xAxis = new int[totalReadings];
  yAxis = new int[totalReadings];
  zAxis = new int[totalReadings];

  for (int i=0; i < totalReadings; i++){
    xAxis = oneGSensorValue;
    yAxis = oneGSensorValue;
    zAxis = oneGSensorValue;
  }

  myPort = new Serial(this, Serial.list()[0], baudRate);
  myPort.bufferUntil(lf);

  noLoop();
}

void draw()
{
  background(#e3e2dc);
  drawGraph(xAxis, 195, color(#b7b093), "X - Axis"); 
  drawGraph(yAxis, 295, color(#7fcccf), "Y - Axis");
  drawGraph(zAxis, 395, color(#d78492), "Z - Axis");
  draw3d(currentX, currentY, currentZ);
}

void drawGraph(int[] arrToDraw, int yPos, color graphColor, String name){
  int arrLength = arrToDraw.length;
  stroke(graphColor);
  for (int x=1; x<arrLength - 1; x++) {
    float normalizedLine = norm(arrToDraw
  • , 0.0, 700.0);
        float lineHeight = map(normalizedLine, 0.0, 1.0, 0.00, 85.0);
        float normalizedLine2 = norm(arrToDraw[x-1], 0.0, 700.0);
        float lineHeightPrev = map(normalizedLine2, 0.0, 1.0, 0.00, 85.0);
        line(x-1, yPos- int(lineHeightPrev), x, yPos - int(lineHeight));
      }
      pushStyle();
      smallFont();
      //stroke(#888888);
      fill(graphColor);
      String gString = nfc(gFromSensorValue(arrToDraw[arrLength - 2]), 2);
      text(name + " : " + gString + " Gs", 10, yPos - 10);
      popStyle();
    }

    void draw3d(int currentX, int currentY, int currentZ){
      float normalizedX = norm(currentX, 0.0, 700.0);
      float normalizedY = norm(currentY, 0.0, 700.0);
      float normalizedZ = norm(currentZ, 0.0, 700.0);
      float finalZ = map(normalizedZ, 0.0, 1.0, 0, 200);
      float finalY = map(normalizedY, 0.0, 1.0, -5, 5);
      float finalX = map(normalizedX, 0.0, 1.0, -5, 5);

      pushMatrix();
      ambientLight(102, 102, 102);
      lightSpecular(204, 204, 204);
      directionalLight(102, 102, 102, -1, -1, -1);
      shininess(1.0);
      translate(400, finalZ);
      rotateY(finalY + 1.0);
      rotateZ(finalX);
      fill(#67f198,95);
      noStroke();
      float heightWidth = finalX * 1.8;
      box(100, 100, 5);
      popMatrix();
    }


    int[] insertValueIntoArray(int[] targetArray, int val, int pos, int maxLength){
       if(pos > (maxLength-1)){
         // if the pos == maxSize, shift the array to retain the original value
         int[] returnArray = subset(targetArray, 1, maxLength-1);
         returnArray = expand(returnArray, maxLength);
         returnArray[maxLength-2] = val;
         return returnArray;
       }else{
         targetArray[pos] = val;
         return targetArray;
       }
    }
    float gFromSensorValue(int sensorValue){
      //convert analog value into millivolts
      float mvValue = sensorValue * 4.9;
      return mvValue/oneGMillivolt;
    }

    void smallFont(){  textFont(font, 12); }
    void mediumFont(){ textFont(font, 12); }
    void largeFont(){  textFont(font, 12); }

    void serialEvent(Serial p){
      String inString;
      try{
        inString = (myPort.readString());
        currentX = xValue(inString);
        currentY = yValue(inString);
        currentZ = zValue(inString);
        xAxis = insertValueIntoArray(xAxis, currentX, readingPos, totalReadings);
        yAxis = insertValueIntoArray(yAxis, currentY, readingPos, totalReadings);
        zAxis = insertValueIntoArray(zAxis, currentZ, readingPos, totalReadings);
        readingPos = readingPos + 1; // increment the array position
      }catch(Exception e){
       println(e);
      }
      redraw();
    }

    int xValue(String inString){
      int pipeIndex = inString.indexOf('|');
      return int(inString.substring(0,pipeIndex));
    }

    int yValue(String inString){
      int pipeIndex = inString.indexOf('|');
      int colonIndex = inString.indexOf(':');
      return int(inString.substring(pipeIndex+1, colonIndex));

    }
    int zValue(String inString){
      int colonIndex = inString.indexOf(':');
      return int(inString.substring(colonIndex + 1, inString.length() - 2));
    }[/i]


    Thanks!

Go Up