Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Pointers to functions! HELP needed. on: September 20, 2012, 10:49:37 am
Thank you!

This small detail killed about 2 hours of my time. smiley
2  Using Arduino / Programming Questions / Pointers to functions! HELP needed. on: September 20, 2012, 10:37:20 am
Hello,

I know that maybe this topic already exists but I didn't found it.
I am new to pointers and trying to find out how they work! The code is as follows :

Code:
void (*functii[2])(void);
char stare = 'o';

void setup()
{
  Serial.begin(9600);
 
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}
void functie1(void)
{
  digitalWrite(13,HIGH);
  Serial.println("APRINS");
  functii[1] = functie1;
  functii[2] = functie2;
}
void functie2(void)
{
  digitalWrite(13,LOW);
  Serial.println("STINS");
}
void loop()
{
 
 if (Serial.available() > 0){
   stare = Serial.read();
   Serial.println(stare);
 if (stare == 'a')
 {
  functii[1];
 }
 else if(stare == 's')
{
  functii[2];
}
 }
 
}

My question: Is this not supposed to work?
Is there another way of using pointers?

Thank you!
 smiley
3  Using Arduino / Project Guidance / Re: Advice needed using PID Library on: April 22, 2011, 01:33:21 am
I want the PID to control the speed of the robot. The speed of the robot in concern with the distance of the objects and wall.
The one that I have now doesn't have a good trajectory because it doesn't go on a straight line. I want to correct that with the PID.

Thanks
4  Using Arduino / Project Guidance / Advice needed using PID Library on: April 21, 2011, 09:02:59 am
Hello
I am now trying for the first time to use the PID. The thing I am trying to build is a Maze solving and obstacle avoiding robot. The code that I have now doesn't have any kind of PID. And it looks like this:
Code:
int enaA = 3;
int in1a = 10;
int in2a = 11;
int enaB = 5;
int in1b = 9;
int in2b = 6;

void setup(){
   pinMode(enaA, OUTPUT);
  pinMode(enaB, OUTPUT);
  pinMode(in1a, OUTPUT);
  pinMode(in1b, OUTPUT);
  pinMode(in2a, OUTPUT);
  pinMode(in2b, OUTPUT);
  Serial.begin(9800);
}

void loop(){
  SharpIR(0,1,2);
 
}

void SharpIR(int a, int b, int c){
  int cita[5];
  int citb[10];
  int citc[5];
  int suma = 0;
  int avga = 0;
  int sumb = 0;
  int avgb = 0;
  int sumc = 0;
  int avgc = 0;

  if(a<=15){ // reads a 5 times and makes the average to get e more correct reading
   for(int i = 0; i<5;i++){
    cita[i] = analogRead(a);
    delay(1);
  }
  for(int i = 0; i<5; i++){
    suma += cita[i];
  }
  avga = suma/5;
  }

  if(b<=15){// reads b 5 times and makes the average to get e more correct reading
    for(int i = 0; i<10;i++){
    citb[i] = analogRead(b);
    delay(5);
  }
  for(int i = 0; i<10; i++){
    sumb += citb[i];
  }
  avgb = sumb/10;
  }

  if(c<=15){// reads c 5 times and makes the average to get e more correct reading
    for(int i = 0; i<5;i++){
    citc[i] = analogRead(c);
    delay(1);
  }
  for(int i = 0; i<5; i++){
    sumc += citc[i];
  }
  avgc = sumc/5;
  }
  Serial.print("A: ");
  Serial.print(avga);
  Serial.print("; B: ");
  Serial.print(avgb);
  Serial.print("; C:");
  Serial.print(avgc);
  Serial.println("");
 
  if(avgc >=300 && avgb <=400){
    if(avgc <=350){
      analogWrite(enaB, 255);
      analogWrite(enaA, 255);
      analogWrite(in1a, 0);
      analogWrite(in2a, 255);
      analogWrite(in1b, 0);
      analogWrite(in2b, 255);
      Serial.println("inainte");// inainte = forward in romanian
    }
  }
  if(avgc <=300 && avgc >=250 && avgb <=400){
    analogWrite(enaB, 255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 255);
    analogWrite(in1b, 0);
    analogWrite(in2b, 200);
    Serial.println("dreapta");// dreapta = right in romanian
   
  }
  if(avgc <=250 && avgc >=200 && avgb <=400){
    analogWrite(enaB, 255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 255);
    analogWrite(in1b, 0);
    analogWrite(in2b, 150);
    Serial.println("dreapta1");
   
  }
  if(avgc <=200 && avgc >=0 && avgb <=400){
    analogWrite(enaB, 255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 255);
    analogWrite(in1b, 0);
    analogWrite(in2b, 0);
    Serial.println("dreapta2");
   
  }
  if(avgc >=350 && avgc <=400 && avgb <=400){
    analogWrite(enaB, 255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 200);
    analogWrite(in1b, 0);
    analogWrite(in2b, 255);
    Serial.println("stanga");// stanga = left in romanian
   
  }
  if(avgc >=400 && avgc <=450 && avgb <=400){
    analogWrite(enaB, 255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 150);
    analogWrite(in1b, 0);
    analogWrite(in2b, 255);
    Serial.println("stanga1");
   
  }
  if(avgc >=450 && avgc <=500 && avgb <=400){
    analogWrite(enaB,255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 0);
    analogWrite(in1b, 0);
    analogWrite(in2b, 255);
    Serial.println("stanga2");
   
  }
  if(avgc >=500 && avgc <= 700 && avgb <=400){
    analogWrite(enaB,255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 0);
    analogWrite(in1b, 0);
    analogWrite(in2b, 255);
    Serial.println("stanga3");
   
  }
  if(avgb >=400){
//    if(avgc >=300){
    analogWrite(enaB, 255);
    analogWrite(enaA, 255);
    analogWrite(in1a, 0);
    analogWrite(in2a, 0);
    analogWrite(in1b, 0);
    analogWrite(in2b, 255);
    Serial.println("Stanga obstructie");
//    }
  }
}

The setup that i use is 3 Sharp IR distance sensors and a Tamyia double gearbox double DC motors. It also uses the L298 motor driver.
My questions are:
     - If I have the 3 sensors how do I store the readings and make the difference? see code below.
     - I have 3 sensors and only 2 motors... to many output variables?
     - How can I correct the mistakes made in the code below?
Code:
#include <PID_v1.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;
double Setpoint1, Input1, Output1;
double Setpoint2, Input2, Output2;
....
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
PID myPID1(&Input1, &Output1, &Setpoint1,2,5,1, DIRECT);
PID myPID2(&Input1, &Output1, &Setpoint1,2,5,1, DIRECT);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(0);
...
  Setpoint = 100;
...

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
...
}
void loop(){
SharpIR(0,1,2);
}
SharpIR(int a, int b, int c){
Input = analogRead(a);
Input1 = analogRead(b);
...

 if(Input >=300 && Input1 <=400){
    if(Input <=350){
// speed control from enable
      analogWrite(enaB, Output);
      analogWrite(enaA, Output);
// Motors are always going forward
      analogWrite(in1a, 0);
      analogWrite(in2a, 255);
      analogWrite(in1b, 0);
      analogWrite(in2b, 255);
      Serial.println("inainte");// inainte = forward in romanian
    }
  }
....
}

Thank You
5  Using Arduino / Installation & Troubleshooting / Re: Arduino not recieving programs from the computer. on: March 18, 2011, 03:13:45 am
Now go to serial monitor and type any key in. If it echoes back it communicates.
If that is the case the try uploading a sketch. maybe there was a wrong contact.

6  Using Arduino / Installation & Troubleshooting / Re: Arduino not recieving programs from the computer. on: March 17, 2011, 01:15:48 pm
If you said that on your dad's computer works and on yours doesn't.
Are you sure you have selected the correct COM port and the correct board from the tools menu in the Arduino IDE?

Still see if it is communicating correctly.

Good Luck
7  Using Arduino / Installation & Troubleshooting / Re: Arduino not recieving programs from the computer. on: March 17, 2011, 12:15:34 pm
If you have the Duemilanove it shouldn't be that hard to take it of. You need to do this to find out if there is a problem with the microcontroller or with the board.
Just put a screwdriver under it and it should come out.
Then place a jumper between the 2&3 pins and go to Serial monitor in the Arduino IDE and see if you recieve anything.

Good Luck
8  Using Arduino / Installation & Troubleshooting / Re: Arduino not recieving programs from the computer. on: March 16, 2011, 02:30:13 pm
Maybe this will help. It is the problem I had and solved. My problem was with a home made Arduino.

http://arduino.cc/forum/index.php/topic,55316.0.html

Hope this helps
9  Using Arduino / Installation & Troubleshooting / Re: Arduino not recieving programs from the computer. on: March 16, 2011, 02:28:27 pm
The problem I had was a capacitor. If you have a oscciloscope and see if the ATmega chip resets correctly.
This error is also due to bad communication between the computer and the Arduino. You can also remove the ATmega from the Arduino and put a jumper between the 2&3 pin and see if it responds in the Serial Monitor.
You may also have a bad USB cable. That happend to me once. One minute it was working and then nothing and the same error.

Please follow-up if any of them worked.
10  Using Arduino / Installation & Troubleshooting / Re: (Solved) Home made Arduino problems. on: March 16, 2011, 12:16:12 pm
Hi. I have solved the problem of uploading via FTDI Basic Breakout board on the ATmega328.
The problem was the reset. On the DTR it needed a capacitor.
It was my mistake of not seeing it on the schematic.

11  Using Arduino / Installation & Troubleshooting / Re: Arduino not recieving programs from the computer. on: March 16, 2011, 02:28:27 am
Are you running windows 7 x64 on it?
If this is the case maybe you want to go to the core.a and go to properties, advanced and remove the "encrypt contents to secure data" mark.

Hope this helps.
12  Using Arduino / Installation & Troubleshooting / Re: Home made Arduino problems. on: March 15, 2011, 03:51:46 am
It was with the bootloader pre-burned on it. After some failed attempts I re-burned the bootloader using Arduino as ISP.
To test that it is working properly I swapped the controllers and put the fresh burned one in the Arduino to see if it is working. It worked great, still does.
I don't think that is the problem. I think the problem is the two 22pF capacitors which seem to be different, one is brown and on it is written 22J and the other is blue and on it is written on one line 22 and on the other 2000V. Maybe something is not working there.

Still my question remains. How can I upload a sketch on the Arduino Duemilanove using the FTDI Basic breakout board from Sparkfun?

Thanks 
13  Using Arduino / Installation & Troubleshooting / Re: Home made Arduino problems. on: March 14, 2011, 02:44:08 pm
@Nishant, thanks for the advice, I already tried that and it did not work. But it looks like the board resets it .

@Coding Badly, thanks for helping. I tried both ways. Connecting the RX from the breakout board to TX on the microcontroller and TX from microcontroller to RX on the FTDI.

If it is of any use, I have used as a model the schematic of Arduino Pro, where I saw that between the FTDI chip and the microcontroller there were no parts, it is directly connected.

The big concern is why can't I upload sketches on the Duemilanove via external FTDI chip?
14  Using Arduino / Installation & Troubleshooting / (Solved) Home made Arduino problems. on: March 14, 2011, 12:33:15 pm
I'm sorry if this is not the place to post this kind of topic. I didn't know where to post it. If a moderator does consider it is misplaced please move it to the correct category.

The setup is very simple, one ATmega328 with bootloader burned on. Two 22pF capacitors, 16MHz Quartz, reset button, 10kOhm resistor and 560Ohm resistor with led connected on digital pin 13. I want to program this using a FTDI Basic 5v breakout board from SparkFun.
The problem is that i keep getting a error message and it does not upload.
The error is:
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
Before this message the board resets itself and then the tx led on the FTDI breakout board blinks 3 times, pauses and then one more time, and then the error.
I have tried the following to get to a solution:
     -Verify that the right board and COM port are selected.
     -Reinstall the FTDI Drivers.
     - Verify that the baud rate in boards.txt is ok.
     -Search for short-circuit or open-circuits that should not be on the schematic.
     -Tested the ATmega328 on my Duemilanove that I bought earlier. It works great, I can upload on the microcontroller.
     -Tested two USB cables, none of them are faulty.
     -Tested the FTDI by making a short-circuit between rx and tx and listening to it in Serial Monitor, it works great.
     -Tried and failed to upload a sketch thru the FTDI on the Duemilanove...I don't understand this.
     -Tried on other computers with different operating systems, same error.

At first I thought that  the FTDI chip is fried, or the ATmega328 now I know that they are working, but why not together?
And also I don't know why it does not upload the sketch to the Duemilanove and it does on the Arduino Pro.

Thanks  
15  Using Arduino / Installation & Troubleshooting / Re: Window 7 x64 unable to access Arduino MEGA 2560.inf on: January 28, 2011, 03:43:28 am
If you go to Device Manager and plug in the Uno, what shows up? USB Serial Device or Unknown Device or Arduino Uno with exclamation mark?
If you have USB Serial Device, I got that for Windows XP with the duemilanove, you should install the above driver, this is not the case since it does not have the FTDI chip.
If you have unknown device, that is what happened with Mega on Windows 7, I had to install the USB to serial COM driver, and the it showed the Arduino Mega with exclamation mark and installed the Mega using the .inf file.

Hope this helps.
Good Luck 
Pages: [1] 2