Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 14
61  Using Arduino / Programming Questions / Re: Amarino accelerometer on: December 24, 2012, 01:34:21 pm
Same results with comparison operators modified.

Code:
#include <MeetAndroid.h>

#define Forwardled 3  
#define Reverseled 11  
#define Rightled 5  
#define Leftled 6

float data[3] = {
  0};
int intdata[3] = {
  0};
int i = 1;


MeetAndroid meetAndroid(error);

void error(uint8_t flag, uint8_t values)
{
  Serial.print("ERROR: ");
  Serial.print(flag);
}


void setup() {
  Serial.begin(9600);      
  pinMode(Forwardled, OUTPUT);
  pinMode(Reverseled, OUTPUT);
  pinMode(Leftled, OUTPUT);
  pinMode (Rightled, OUTPUT);
  delay(1000);

  meetAndroid.registerFunction(floatValues, 'A');

}

void loop()
{
  meetAndroid.receive();
}

void floatValues(byte flag, byte numOfValues)
{

  meetAndroid.getFloatValues(data);

  for (int i=0; i<3;i++)
  {
    meetAndroid.send(data[i]);
  }


  //This is for Forward/Reverse
  if ((data[0] >= -10) && (data[0] <=10))    
  {
    intdata[0] = int(data[0]);
    intdata[0] = intdata[0] * 24;

    if (data[0] <= -2)
    {
      intdata[0] = abs(intdata[0]);
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Forwardled, intdata[0]);
    }

    else if (data[0] >= 2)
    {
      digitalWrite(Forwardled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Reverseled, intdata[0]);
    }

    else if ((data[0] >= -1) || (data[0] <= 1))  
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }
  }

  //This is for Turn Left/Turn Right
  if ((data[1] >= -10) && (data[1] <= 10))
  {
    if (data[1] <= -2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Rightled, intdata[0]);
    }

    else if (data[1] >= 2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Rightled,LOW);
      analogWrite(Leftled, intdata[0]);
    }

    else if ((data[1] >= -1) || (data[1] <= 1))  
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }    
  }
}

62  Using Arduino / Programming Questions / Amarino accelerometer on: December 24, 2012, 12:41:16 pm
I'm trying to use Amarino to send data from my android phone's accelerometer to arduino in order to turn on or off four led lights that simulate the direction of a robot consisting of two motors. The motors can go forward or reverse. The code is copied and modified from this: http://www.instructables.com/id/Hercules-The-Motion-Controlled-Android-Robot/step8/Step-8-Programming-the-Arduino/

I would expect from my modified code that when I tilted the phone forward on the x axis, the forward light would turn on. When I tilt the phone backward on the axis, the backward led turns on. When the phone is tilted right on the y axis, the right led is turned on, and when the phone is tilted left, the left led is turned on. If the phone is tilted purely on the axis, only one led should be on at a time, but if the phone is tilted simultaneously on the x and y axis, two leds should be on at one time and by using pwm, should be lit with a brightness corresponding to the angle of the tilt. ex. forward-right, back-left, etc.

However, this is not the case. When the phone is tilted forward, no lights. When the phone is tilted backward, no lights.
When the phone is tilted right,the right led comes on, and when it is tilted left the left led comes on. it seems to work the right and left lights seem to work best when it is tilted diagonally in any of the four diagonal directions. But the most I can ever see on the forward and reverse is a barely detectable flicker when the phone is tilted in one of the diagonal directions.

Originally I tried to modify the origional code to drive two motors using an h bridge but got the same results as the leds. I wired up the leds as a simple simulation to try to find a problem. I've tried to change the baud rates, but my program works the same at 9600, 57600, or 115200.

Here is my code:
Code:
#include <MeetAndroid.h>

#define Forwardled 3  
#define Reverseled 11  
#define Rightled 5  
#define Leftled 6

float data[3] = {
  0};
int intdata[3] = {
  0};
int i = 1;


MeetAndroid meetAndroid(error);

void error(uint8_t flag, uint8_t values)
{
  Serial.print("ERROR: ");
  Serial.print(flag);
}


void setup() {
  Serial.begin(57600);      
  pinMode(Forwardled, OUTPUT);
  pinMode(Reverseled, OUTPUT);
  pinMode(Leftled, OUTPUT);
  pinMode (Rightled, OUTPUT);
  delay(1000);

  meetAndroid.registerFunction(floatValues, 'A');

}

void loop()
{
  meetAndroid.receive();
}

void floatValues(byte flag, byte numOfValues)
{

  meetAndroid.getFloatValues(data);

  for (int i=0; i<3;i++)
  {
    meetAndroid.send(data[i]);
  }


  //This is for Forward/Reverse
  if (-10<=data[0]<=10)            
  {
    intdata[0] = int(data[0]);
    intdata[0] = intdata[0] * 24;

    if (data[0] <= -2)
    {
      intdata[0] = abs(intdata[0]);
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Forwardled, intdata[0]);
    }

    else if (data[0] >= 2)
    {
      digitalWrite(Forwardled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Reverseled, intdata[0]);
    }

    else if (-1<=data[0]<=1)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }
  }

  //This is for Turn Left/Turn Right
  if (-10<=data[1]<=10)  
  {
    if (data[1] <= -2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Rightled, intdata[0]);
    }

    else if (data[1] >= 2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Rightled,LOW);
      analogWrite(Leftled, intdata[0]);
    }

    else if (-1<=data[1]<=1)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }    
  }
}

Any suggestions?
63  Using Arduino / Project Guidance / Re: How do you make pretty arduino schematics? on: November 30, 2012, 07:15:23 pm
Wizdum,
What did you use for the PCB views on your website? Looks good.
64  Using Arduino / Project Guidance / Re: How do you make pretty arduino schematics? on: November 30, 2012, 01:26:06 pm
So what is a fairly easy and free program for proper schematics editing? Is there one? I have looked at a few programs like PCB Express, TINA TI, Eagle CAD, PCB 123, MultiSim,  etc. It seems that either it's very difficult to find different components, or it's overly time consuming to learn, or it has very few components. I liked National Instruments MultiSim, but it isn't free.
65  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 09:59:07 pm
Thanks Nick,
Good work. You explained that well. I know I can use this down the road when I get my robot going again. It will be useful for ramping up the motors among other things. The sensors won't be interrupted by the "delay()."

How is Melbs? I was there at this time last year. I wish I was there now haha.
66  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 09:26:21 pm
Thanks, Nick. That's what I'm trying to do. In my previous post I said that the first bit example of code that I modified from arrch was working correctly. It isn't. I doesn't increment every 10ms; It increments as fast as it can. The "delay" functions aren't working.  I'll play with it a bit and see if I can get it to work. I know I shouldn't worry about it as the second posted code in my previous post works, but I just like to try to understand things. Maybe there will be a situation where I could modify the code into something useful.
67  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 09:11:19 pm
Code:
int led = 3;
int i = 0;
long interval = 10;
long previousMillis = 0;
int lastcheck = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();
 for (int i=0;i<=255;i++)
{
  if (millis() - lastcheck > interval)
  {
    lastcheck = millis();
    analogWrite (led, i);
  }
  Serial.println (i);
}
}

The above code works as intended. It resets the led to 0 every time through the loop. The following code works in a different way. Once the led reaches 255, it stays there constantly lit. As I said a few times, I'm trying to learn different ways of implementing a delay without "delay()." That's why it "wasn't sticking."
Code:
int led = 3;
int i = 0;
long interval = 10;
long previousMillis = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    analogWrite (led, i++);
    i = constrain (i,0,255);
    Serial.println (i);
  }
 // analogWrite (led, 0);
  //Serial.println (i);
}







68  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 08:30:32 pm
Thanks Billroy. That works. I had to add a line to constrain i to a maximum of 255.
 
Code:
int led = 3;
int i = 0;
long interval = 10;
long previousMillis = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    i = min (i, 254);            sets pwm to 255 maximum
    analogWrite (led, i++);
    Serial.println (i);
  }
}


Although this works to turn the light on, I am still curious how to fix my origional code. Fading the light is just something I picked to try to get to understand the "blink without delay." That really was the origional question. I suppose the question is: how do I use the "blink without delay" with a for loop? Any ideas would be greatly appreciated
69  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 08:09:36 pm
I am trying to slow the loop down by trying to use the "blink without delay." Are you saying that there is no way to slow the for loop down without using delay()?
It does work without any delay() like this:
Code:
for (int i = 0; i <=255; i++){
    analogWrite (led, i);
    Serial.println (i);
70  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 07:53:16 pm
It doesn't take long at all to "rip" through the loop. The point isn't fading the led. The point is trying to understand "blink without delay" in a concept other than blinking a light.
71  Using Arduino / Programming Questions / pwm with delay on: November 25, 2012, 07:12:08 pm
Hello,

In order to try to get my head around the "blink without delay" concept, I have run into a wall. I am trying to use pwm to turn on the led and modify the blink without delay example to replace the "delay (50);" I think you can see what I'm trying to do through the code. Unfortunately the light never comes on and I always get 0 in the serial monitor. Can anybody shed some light for me? Thanks in advance.
I'm trying to replace this:
Code:
int led = 3;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  for (int i = 0; i <=255; i++){
    analogWrite (led, i);
    delay (50);  
    Serial.println (i);
  }
}

with this:
Code:
int led = 3;

long interval = 50;
long previousMillis = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();

  for (int i = 0; i <=255; i++){
    if (currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;
      analogWrite (led, i);

      Serial.println (i);
    }
  }
}
72  Using Arduino / Sensors / Re: Distance Sensor on: November 18, 2012, 09:01:43 pm
for people detection, you probably want the ez-0 or ez-1. But they aren't reliable for people detection. You would be better off buying a cheap ultrasonic sensor and try teckel's newping library.

http://code.google.com/p/arduino-new-ping/
73  Topics / Robotics / Re: Read Android sensor and send it to Arduino using Bluetooth? on: November 15, 2012, 08:56:54 pm
http://www.instructables.com/id/Reverse-Engineering-Uzzors2k-Bluecar-Android-App/step1/Amarino/

http://www.amarino-toolkit.net/
74  Using Arduino / Project Guidance / Re: Android talking to Arduino on: November 12, 2012, 06:17:53 pm
http://www.instructables.com/id/Reverse-Engineering-Uzzors2k-Bluecar-Android-App/step1/Amarino/

http://www.amarino-toolkit.net/
75  Using Arduino / Project Guidance / Re: Grove starter kit on: November 03, 2012, 06:58:45 am
Code:
void setup()
{
 Serial.begin(9600); 
}
Maybe this is what you need to add? This sets the data rate so that you can communicate with your computer through the serial monitor.
 
According to the description on the link, the tilt switch should be read like a button (digital input). It says that when the switch is level, the button is open, and when it is tilted, the switch closes. Why are you including serial libraries? Get rid of them and try this:
http://arduino.cc/en/Tutorial/Button Just use the tilt switch as the button. Did you read this link provided on the main page of the link you provided? http://www.seeedstudio.com/wiki/index.php?title=GROVE_-_Starter_Kit_v1.1b#Grove_-_Tilt_switch
It walks you right through set up and a simple example project including the code.

You have started threads all over the place covering various subjects in a very short period of time. You will learn much more, be more successful, and be much much happier and satisfied in the long run if you do one thing at a time. In just a few days you have started threads and asked for help about this tilt sensor, motor drivers, ultrasonic sensors, servos, joysticks, serial lcd's, and photo resistors. This tilt sensor would be a good project to start with, but read and watch some arduino and electronics tutorials. I gave you a couple good links in another thread, or you can find some others. Start out slow and experiment.

When posting code, use the code tag tool. You can just highlight the code that you pasted and hit the '#' key much like you do when you post a link.

Good luck
Pages: 1 ... 3 4 [5] 6 7 ... 14