Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Programming Questions / Re: Boe-bot for arduino roaming with ping on servo turret on: February 12, 2013, 12:29:00 pm
Check which pins your using for servo timing and motor control. For example, the standard servo.h lib is not compatible with the standard motor shield.

Mark


The bot uses two servos to move it one for the left and one for the right wheel. Those two servos have some modification that makes them a continuous rotation servo motor, they also have a potentiometer for calibrating the speed so they both move the bot strait. But it can be a pain to keep the two servos even and calibrated.
17  Using Arduino / Programming Questions / Boe-bot for arduino roaming with ping on servo turret on: February 12, 2013, 06:49:11 am
I have been trying to find out why the boe-bot jacks the turret to the left and starts turning in circles to the left. When the boe-bot encounters a corner. If I put an object in front of the sensor while its in its retard turn it snaps out of it and starts to move around like normal. Knowing C++ fairly well I can see in the sketch the author may have had a major lack of concentration because I see a lot of first grader mistakes and "WTF's?".

Others have had this issues and their fix was ether new battery's or a bad ground. Well that's not the problem with this bot, all fresh batteries, connections to the circuit are fine and everything works.

I have tried to find help on the parallax forum and other parts of their site but it seems to me their company or users have a major bias towards arduino and do not support the arduino shield as well as their own micro controller even though they said they would.

I think its programing. Am I wrong?

Here is a link to the sketch:
http://learn.parallax.com/project/let-it-roam
18  Using Arduino / Programming Questions / Re: redefined variable issues arduino IDE on: February 11, 2013, 07:33:24 am
Note, under some warning levels (which we don't appear to have turned on) you would get a warning about a "shadowed" variable "i". The warning is because, although it isn't illegal, possibly you did not intend to redefine "i".

Is there a way to turn on all warning's from my side?

I would like the strictest warning levels.
19  Using Arduino / Programming Questions / Re: redefined variable issues arduino IDE on: February 10, 2013, 10:21:53 am
So you missed this part?
Quote
A program can have same name for local and global variables but value of local variable inside a function will take preference. For example:
Code:
#include <iostream>
using namespace std;
 
// Global variable declaration:
int g = 20;
 
int main ()
{
  // Local variable declaration:
  int g = 10;
 
  cout << g;
 
  return 0;
}
When the above code is compiled and executed, it produces following result:

10


You might be further amused to know that each block {} is a separate scope:
Code:
int var = 1;
void setup() {
  Serial.println(var);
  int var = 20;
  Serial.println(var);
  {
    Serial.println(var);
    int var = 300;
    Serial.println(var);
  }
  Serial.println(var);
}

Should display:

20
20
300
300
20

No I didn't miss that part. A global variable has a much wider scope then a local variable and if the compiler does not see it as an error then whats the point in having a "redefinition error" if the compiler doesn't find all the errors in the variables scope.

It's giving priority over one variable scope then the other!
20  Using Arduino / Programming Questions / Re: redefined variable issues arduino IDE on: February 10, 2013, 09:42:11 am
It's only a redefinition if you do it in the same scope.  Each function is a different scope and can have local variables with the same name as a variable in Global scope.

You just have to be careful about your use of variables.

And don't give global variables stupid names like 'i'. smiley

All the other redefined variables are in the same scope as the first defined "i".
Yes each function has its own scope but those variables defined in that scope would be called local variables, when you define a variable in a global scope like the first defined "i" the hole sketch is its scope and all the functions in that scope can use "i" and should error if "i" is redefined in those functions and block's.

If I can use "i" in the function before its redefined and after its redefined, then "i" is within that scope.

This link doesn't explain the issue but can give you an idea of what global and local scope variables are.
http://www.tutorialspoint.com/cplusplus/cpp_variable_scope.htm
21  Using Arduino / Programming Questions / redefined variable issues arduino IDE on: February 10, 2013, 08:31:24 am
I have found the arduino IDE is not finding all redefined variables in a sketch. This can lead to major programing issues that the compiler should catch!


This is my example code and the IDE versions tested and failed are 1.0.3 and 1.5.2

Code:
//Compiler dose not find all redefinition error's in the sketch

// define i in this scope
int i = 0;

// Uncomment 'int i' and we will get redefinition error
//int i = 1;


void setup() {
// we should get redefinition error here
int i = 1;
}

void loop() {
// we should get redefinition error
int i = 1;
}
22  Using Arduino / Programming Questions / Re: Compiling on Linux vs Windows? on: December 20, 2012, 05:54:29 am
That's not the correct place for third-party libraries. They should go, as PaulS said, in the libraries subdirectory of your sketchbook directory.

Just out of curiosity, what's the reasoning behind this advice?

Given that 3rd party libraries have, in the past, been Arduino-version-specific, doesn't it make more sense to keep the libraries within the relevant Arduino installation? By my understanding they behave the same in either case and it's just a question of whether you want to be able to upgrade the IDE and keep using the same copy of all the 3rd party libraries, or [need to] install a separate copy for each IDE version.

Well I was thinking there should be an add-on library, but didnt know where it was.
23  Using Arduino / Programming Questions / Re: Compiling on Linux vs Windows? on: December 19, 2012, 07:29:05 am
Your new library is the github folder "AS3935" copy that folder with all the files and examples folder.
in the arduino install folder "xxx\arduino-1.0.x\libraries" make sure its "libraries" NOT "lib".


FYI:After install I used the example sketch and it verified fine on win7 64-bit, Arduino 1.0.2
24  Using Arduino / LEDs and Multiplexing / Re: Help with code for multiplexing LED Display on: December 17, 2012, 07:30:54 am
I found this perl module for symon's signs and it works, with speakers.

The perl module uses Ethernet to talk to the sign, most signs with Ethernet run off port 700 but can be changed.
The module requires 'Digest::CRC' and 'IO::Socket::INET' installed, so since 'IO::Socket::INET' should be installed in the perl library by default 'Digest::CRC' should be the only thing you would need to install.
You will have to set the size of your sign in the program and then have fun.

sudo cpan install Digest::CRC

https://github.com/bwilber/Net-Symon-Netbrite
25  Using Arduino / Project Guidance / Re: Electronic Saxophone on: December 12, 2012, 06:57:20 am

Yes sir

that's about the best you can get when using a single frequency for one tone.
For a more stereo quality sound what some people are doing is pre-recording the sounds then using a stereo IC and the arduino to mix it.

http://www.instructables.com/id/Electronic-Instrument/
http://www.instructables.com/id/Stereo-Audio-with-Arduino/
http://www.instructables.com/id/Arduino-Vocal-Effects-Box/
26  Using Arduino / Project Guidance / Re: Electronic Saxophone on: December 11, 2012, 08:42:13 am
I understand that, but do you have any suggestions sir so that my project can be near to the sound of the actual saxophone?

Does it sound like MIDI tones?
27  Using Arduino / Programming Questions / Re: PWM - Peltier working code on: December 07, 2012, 12:27:24 pm
I still had bugs in the display, but finaly worked them out.
Heres the code and pic , take a look and comment.
Code:
/*
4 - 10k resistors

2 - TMP36 - temperature sensor - 5volt
For more details on this circuit: http://tinyurl.com/c89tvd
I used a 10k ohm resistor on Vout to-> ground to protect the arduino pin

1 - Serial 7 Segment Display Sparkfun Datasheet - 3.3volt
https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Serial-7-Segment-Display-Datasheet

1 - MOSFET RFP30N06LE or RFP30N06L
http://bildr.org/2012/03/rfp30n06le-arduino/

1 - TEC1-12709 - Sealed Peltier - 12volt
maxVolts - 15.4
maxAmps  - 9
maxWatts - 138.6

1 - Pushbutton - 5volt
http://arduino.cc/en/Tutorial/Button

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);    // nuelectronics lcd-shield v1.1

int numCols = 16;
int numRows = 2;
/*

/* This is a simple program to test the 4 diget Sparkfun 7 segment serial LED display */
#include <SoftwareSerial.h>

#define rxPin 255 // 255 because we don't need a receive pin
// Connect the Arduino pin 3 to the rx pin on the 7 segment display
#define txPin 3

// set up a new serial port
SoftwareSerial LEDserial=SoftwareSerial(rxPin, txPin);

#define ARY_LEN(a) (sizeof(a)/sizeof(a[0]))

/* Pin 3 for display- delay only,
   Pin 8 for CoolDown- delay only,
   Pin 5 PWM Peltier- full function */
const int PWM_pin[]                = { 3,   8,    5   };   // Pin numbers used
const unsigned long Fade_delayMs[] = {1000, 1000, 80  };
const int Fade_start[]             = { 175, 175,  250 }; // This can be 0 to 254
const int Fade_end[]               = { 255, 255,  255 }; // this can be PWMstart+1..255
const int Fade_step[]              = { 1,   1,    1   };
unsigned int Fade_direction[]      = { +1,  +1,   +1  };  // Fade direction for each pin
int Fade_value[]                   = {  0,   0,   0   };
unsigned long Fade_prevMillis[]    = {  0,   0,   0   };
unsigned long currentMillis;

/* TMP36 temperature sensor on Analog-in A0 & A1 Pin's */
int temperaturePin = 0; // Hot sensor
int temperaturePin2 = 1; // Cold sensor
/* Temp Logic veriables */
float temperature = 0;
int nexttempPin = 0;
int StartCooldown = 0;
int tempSet;

/* Push Button values */
const int buttonPin = 2;     // the number of the pushbutton pin
unsigned int currentTemp = 2; // controles, 1 = celcius, 2 = farenheit
int buttonState = 0;         // variable for reading the pushbutton status

void CheckTemp() {
 temperature = getVoltage(temperaturePin);
 temperature = (((temperature - .5) * 100)*1.8) + 32;
}
/* Over temperature protection */
void CoolDown() {
 CheckTemp();
 if (temperature <= 80) StartCooldown = 0;
}

void pwmOut(int fadeNum, int value) {
 CheckTemp();
 if (temperature >= 100) {
  analogWrite(5, 0);
  StartCooldown = 1;
 }
  else if (temperature >= 95) {
  analogWrite(5, 0);
 }
  else {
  analogWrite(PWM_pin[fadeNum], value);
 }
}

/* to run a simulation 
void lcdOut(int fadeNum, int value) {
    int col, row;
    if (fadeNum <= 3) {
        row = 0;
        col = fadeNum * 4;
    }
    else {
        row = 1;
        col = (fadeNum - 4) * 4;
    }
    lcd.setCursor(col, row);
    lcd.print("    ");
    lcd.setCursor(col, row);
    lcd.print(value, DEC);
}
*/

/* 4 diget, 7-segment serial display, SparkFun
 Set as PWM_pin 3 to only use an ajustable 1000ms delay and not fading part of the method */
void LEDdisplay() {
 
 LEDserial.print('v'); // this is the reset display command
 
 if (nexttempPin == temperaturePin) nexttempPin = temperaturePin2;
 else nexttempPin = temperaturePin; 
 
 temperature = getVoltage(nexttempPin);  //getting the voltage reading from the temperature sensor
 
 if (currentTemp == 1) temperature = (temperature - .5) * 100;
 else temperature = (((temperature - .5) * 100)*1.8) + 32;
 
 LEDserial.print('w'); // send the command char for decimal control
 temperature += 0.001f; // ensure hundredth place
 
 if (temperature < 100 && temperature >= 0
  || temperature > -10 && temperature <=  0){
  if (nexttempPin == temperaturePin2) LEDserial.write(0b00100010);
  else LEDserial.write(0b00000010);
  tempSet = int(temperature*100);
 }
 else if (temperature >= 100 && temperature <= 1000
       || temperature <= -10 && temperature >= -100) {
  if (nexttempPin == temperaturePin) LEDserial.write(0b00000100);
  else LEDserial.write(0b00100100); // turn on apostrophe for temp 2
  tempSet = int(temperature*10);
 }
 else { // some error
  LEDserial.write(0b00111111);
  tempSet = 9999; 
 }
 // 4 place format to fix absent diget alignment.
 if(tempSet<10 && tempSet>=0) LEDserial.print("000");
 else if(tempSet<100&&tempSet>=10) LEDserial.print("00");
 else if(tempSet<1000&&tempSet>=100) LEDserial.print("0");
 else if(tempSet<0 &&tempSet>-10) LEDserial.print("--");
 else if(tempSet>-100&&tempSet<=-10) LEDserial.print("-");
 
 LEDserial.print(tempSet);
}

/* converting from a 0 to 1023 digital range
 to 0 to 5 volts (each 1 reading equals ~ 5 millivolts */
float getVoltage(int pin) {
 return (analogRead(pin) * .004882814);                                       
}

void Fade_outFunc(int fadeNum, int value) {
  // run one or both output functions...
  //lcdOut(fadeNum, value);
  if (StartCooldown == 0 && PWM_pin[fadeNum] == 5)
  pwmOut(fadeNum, value);
 
  if (StartCooldown == 1 && PWM_pin[fadeNum] == 8)
  CoolDown();
 
  if (PWM_pin[fadeNum] == 3)
  LEDdisplay();
}


void setup() {
  //lcd.begin(numCols, numRows);
  //lcd.clear();
 
  // 4 diget, 7-segment serial display, SparkFun
  pinMode(txPin, OUTPUT);
  LEDserial.begin(9600);
 
  // Fade & delay
  for (unsigned int i = 0; i < ARY_LEN(PWM_pin); i++){
    Fade_value[i] = Fade_start[i];
    Fade_outFunc(i, Fade_value[i]);
  }
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}


void Fade_run(int fadeNum) {
  currentMillis = millis();
  if(currentMillis - Fade_prevMillis[fadeNum] > Fade_delayMs[fadeNum]) {
    Fade_prevMillis[fadeNum] = currentMillis;

    Fade_value[fadeNum] += Fade_direction[fadeNum] * Fade_step[fadeNum];
    if (Fade_value[fadeNum] >= Fade_end[fadeNum]) {
      Fade_value[fadeNum] = Fade_end[fadeNum];
      Fade_direction[fadeNum] = -Fade_direction[fadeNum];
    }
    else if (Fade_value[fadeNum] <= Fade_start[fadeNum]) {
      Fade_value[fadeNum] = Fade_start[fadeNum];
      Fade_direction[fadeNum] = -Fade_direction[fadeNum];
    }
    Fade_outFunc(fadeNum, Fade_value[fadeNum]);
  }
}

void loop() {
 /* Push Button */
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH && currentTemp == 2) currentTemp = 1; 
 else if (buttonState == HIGH && currentTemp == 1) currentTemp = 2;

 /* Fade & Delay Loop */
 for (unsigned int i = 0; i < ARY_LEN(PWM_pin); i++)
 Fade_run(i);
}
28  Using Arduino / Programming Questions / Re: PWM - Peltier working code on: December 06, 2012, 09:30:54 am
That'll get you 15. I assume you want 1523. In which case, use this in your snippet:
Code:
int x = int(temp*100.0);

Thats what I ended up with was do a small amout of math to move the decimal point then use int() to cut out the remainder. Nice thanks.
Code:
/*
TMP36 - temperature sensor
For more details on this circuit: http://tinyurl.com/c89tvd
I used a 10k ohm resistor on Vout to-> ground to protect the arduino pin

Serial 7 Segment Display Datasheet
https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Serial-7-Segment-Display-Datasheet

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);    // nuelectronics lcd-shield v1.1

int numCols = 16;
int numRows = 2;
/*

/* This is a simple program to test the 4 diget Sparkfun 7 segment serial LED display */
#include <SoftwareSerial.h>

#define rxPin 255 // 255 because we don't need a receive pin
// Connect the Arduino pin 3 to the rx pin on the 7 segment display
#define txPin 3

// set up a new serial port
SoftwareSerial LEDserial=SoftwareSerial(rxPin, txPin);

#define ARY_LEN(a) (sizeof(a)/sizeof(a[0]))

/* Pin 3 for display- delay only,
   Pin 8 for CoolDown- delay only,
   Pin 5 PWM Peltier- full function */
const int PWM_pin[]                = { 3,   8,    5   };   // Pin numbers used
const unsigned long Fade_delayMs[] = {1000, 1000, 80  };
const int Fade_start[]             = { 175, 175,  250 }; // This can be 0 to 254
const int Fade_end[]               = { 255, 255,  255 }; // this can be PWMstart+1..255
const int Fade_step[]              = { 1,   1,    1   };
unsigned int Fade_direction[]      = { +1,  +1,   +1  };  // Fade direction for each pin
int Fade_value[]                   = {  0,   0,   0   };
unsigned long Fade_prevMillis[]    = {  0,   0,   0   };
unsigned long currentMillis;

/* TMP36 temperature sensor on Analog-in A0 & A1 Pin's */
int temperaturePin = 0; // Hot sensor
int temperaturePin2 = 1; // Cold sensor
/* Temp Logic veriables */
int nexttempPin = 0;
float temperature = 0;
float ConvertTemp = 0;
int StartCooldown = 0;
int tempSet;

/* Push Button values */
const int buttonPin = 2;     // the number of the pushbutton pin
unsigned int currentTemp = 2; // controles, 1 = celcius, 2 = farenheit
int buttonState = 0;         // variable for reading the pushbutton status

void CheckTemp() {
 temperature = getVoltage(temperaturePin);
 temperature = (((temperature - .5) * 100)*1.8) + 32;
}
/* Over temperature protection */
void CoolDown() {
 CheckTemp();
 if (temperature <= 80) StartCooldown = 0;
}

void pwmOut(int fadeNum, int value) {
 CheckTemp();
 if (temperature >= 100) {
  analogWrite(5, 0);
  StartCooldown = 1;
 }
  else if (temperature >= 95) {
  analogWrite(5, 0);
 }
  else if (temperature <= 95){
  analogWrite(PWM_pin[fadeNum], value);
 }
}

/* to run a simulation 
void lcdOut(int fadeNum, int value) {
    int col, row;
    if (fadeNum <= 3) {
        row = 0;
        col = fadeNum * 4;
    }
    else {
        row = 1;
        col = (fadeNum - 4) * 4;
    }
    lcd.setCursor(col, row);
    lcd.print("    ");
    lcd.setCursor(col, row);
    lcd.print(value, DEC);
}
*/

/* 4 diget, 7-segment serial display, SparkFun
 Set as PWM_pin 3 to only use a 1000ms delay and not fading part of the method */
void LEDdisplay() {
 
 LEDserial.print('v'); // this is the reset display command
 
 if (nexttempPin == temperaturePin) nexttempPin = temperaturePin2;
 else nexttempPin = temperaturePin; 
 
 temperature = getVoltage(nexttempPin);  //getting the voltage reading from the temperature sensor
 
 if (currentTemp == 2) ConvertTemp = (((temperature - .5) * 100)*1.8) + 32;
 else ConvertTemp = (temperature - .5) * 100;

   
 LEDserial.print('w'); // send the command char for decimal control
 
 if (ConvertTemp >= 100 && ConvertTemp <= 999
  || ConvertTemp <= -10 && ConvertTemp >= -99.9) {
  SetTemp(1, ConvertTemp);
  if (nexttempPin == temperaturePin2) LEDserial.write(0b00100100); // turn on apostrophe for temp 2
  else if (nexttempPin == temperaturePin) LEDserial.write(0b00000100);
 }
  else if (ConvertTemp >= 1000 && ConvertTemp <= 9999
        || ConvertTemp <= -100 && ConvertTemp >= -999) {
  SetTemp(3, ConvertTemp);
  if (nexttempPin == temperaturePin2) LEDserial.write(0b00100000);
 }
 else if (ConvertTemp < -999 || ConvertTemp > 9999) {
  tempSet = 9999;
 }   
 else {
  SetTemp(2, ConvertTemp);
  if (nexttempPin == temperaturePin2) LEDserial.write(0b00100010);
  else if (nexttempPin == temperaturePin) LEDserial.write(0x02);
 }   
 LEDserial.print(tempSet);
}

void SetTemp(int value, float temp) {
 if (value == 1) { // 999.9 or -99.9 numbers
 temp = temp * 10;
 }
 else if (value == 2) {// 99.99 or -9.99 numbers
 temp = temp * 100;
 }
 // 9999 or -999 numbers too
 tempSet = int(temp);
}

/* converting from a 0 to 1023 digital range
 to 0 to 5 volts (each 1 reading equals ~ 5 millivolts */
float getVoltage(int pin) {
 return (analogRead(pin) * .004882814);                                       
}

void Fade_outFunc(int fadeNum, int value) {
  // run one or both output functions...
  //lcdOut(fadeNum, value);
  if (StartCooldown == 0 && PWM_pin[fadeNum] == 5) pwmOut(fadeNum, value);
 
  if (StartCooldown == 1 && PWM_pin[fadeNum] == 8) CoolDown();
  if (PWM_pin[fadeNum] == 3) LEDdisplay();
}


void setup() {
  //lcd.begin(numCols, numRows);
  //lcd.clear();
 
  // 4 diget, 7-segment serial display, SparkFun
  pinMode(txPin, OUTPUT);
  LEDserial.begin(9600);

  for (unsigned int i = 0; i < ARY_LEN(PWM_pin); i++){
    Fade_value[i] = Fade_start[i];
    Fade_outFunc(i, Fade_value[i]);
  }
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}


void Fade_run(int fadeNum) {
  currentMillis = millis();
  if(currentMillis - Fade_prevMillis[fadeNum] > Fade_delayMs[fadeNum]) {
    Fade_prevMillis[fadeNum] = currentMillis;

    Fade_value[fadeNum] += Fade_direction[fadeNum] * Fade_step[fadeNum];
    if (Fade_value[fadeNum] >= Fade_end[fadeNum]) {
      Fade_value[fadeNum] = Fade_end[fadeNum];
      Fade_direction[fadeNum] = -Fade_direction[fadeNum];
    }
    else if (Fade_value[fadeNum] <= Fade_start[fadeNum]) {
      Fade_value[fadeNum] = Fade_start[fadeNum];
      Fade_direction[fadeNum] = -Fade_direction[fadeNum];
    }
    Fade_outFunc(fadeNum, Fade_value[fadeNum]);
  }
}

unsigned int i = 0;
void loop() {
 /* Push Button */
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH && currentTemp == 2) currentTemp = 1; 
 else if (buttonState == HIGH && currentTemp == 1) currentTemp = 2;

 /* Fade Loop */
 for (i = 0; i < ARY_LEN(PWM_pin); i++) Fade_run(i);
}
29  Using Arduino / Programming Questions / Re: PWM - Peltier working code on: December 06, 2012, 08:35:27 am
The version of sprintf that the arduino uses does not support floats to reduce the amount of memory the library consumes.

so maybe???
Code:
char tBuffer[5];
float temp = 15.2304;
 int x = int(temp);
 sprintf(tBuffer, "%4d", x);
30  Using Arduino / Programming Questions / Re: PWM - Peltier working code on: December 06, 2012, 06:23:12 am
I started to dig around C++ tutes and I seen a few places that say sprintf() can format the value, but i cant figure out how to get it to work on the arduino.

Code:
char tBuffer[5];
float temp = 15.2304;
sprintf(tBuffer, "%2.2f", temp);
// Not sure what to do with tBuffer

I think one of my biggest problems is i dont have an IDE that I can run some test codes on to sort out the logic before i upload it to the arduino.
Pages: 1 [2] 3 4