Show Posts
|
|
Pages: 1 [2] 3 4 ... 10
|
|
16
|
Forum 2005-2010 (read only) / Troubleshooting / Re: Is it possible to make Arduino talk without shield
|
on: June 25, 2010, 09:23:29 pm
|
I was trying to test this code by uploading it to my Arduino board. Unfortunately I always got the same error. What is the problem? The problem is you can't follow directions. I told you in my previous message to make a folder named TTS in the libraries folder under Arduino-0018. Copy all the files there. Perhaps it's not obvious to everyone that there is a sub-folder called examples that has to be copied in the same TTS folder... Make sure the TTStest.pde is located in the examples\TTStest folder when you run it. You can't have the TTS.h and english.h tabs in your code and also import TTS.h from the library... @cr0sh: When I compile the example, I get the following code size on a mega328: Binary sketch size: 10684 bytes (of a 30720 byte maximum)
|
|
|
|
|
17
|
Forum 2005-2010 (read only) / Troubleshooting / Re: Is it possible to make Arduino talk without shield
|
on: June 24, 2010, 08:22:38 pm
|
I managed to translate Webbot's speech synthesis code and made a simple TTS (text to speech) library. But You can't connect just a speaker to a PWM pin, you need to add a RC filter and an amplifier. I used the schematic below:  Also, the code is big and the speech is retro robot like. You can't do anything else during the speech time, but you can do whatever you like before and after the speech is done. Here is the lib: TTS.zip After download, create a TTS folder under Arduino-0018\libraries and place all files there. Then, from Arduino you can open the example provided.
|
|
|
|
|
20
|
Forum 2005-2010 (read only) / Bugs & Suggestions / Re: MegaServo and Wire(I2C)Library conflict
|
on: September 15, 2009, 02:45:22 pm
|
Thanks, I get the idea. But like you said, the fun is to have the servos on this board. I am working on a dual motor controller with I2C interface, perhaps later on I'll separate the servos too, but for now, they will have to work on the main board. Will it be possible to use Timer2 to set up an interrupt to issue the ServoRefresh command every 20ms? If yes, how do I set the Timer2 for that? Any advice on this part?
|
|
|
|
|
21
|
Forum 2005-2010 (read only) / Bugs & Suggestions / Re: MegaServo and Wire(I2C)Library conflict
|
on: September 15, 2009, 09:33:52 am
|
// Includes #include <SoftwareSerial.h> #include <Servo.h> #include <EEPROM.h> #include <Wire.h>
// I2C slaves addresses #define MotorController 60 #define Thermo 208>>1 #define Compass 42>>1
// I2C commands #define Forward 1 #define Reverse 2 #define Left 3 #define Right 4 #define Stop 5
// LCD pins #define txPin 2 // digital pin 2 #define rxPin 13 // digital pin 13, not used for the LCD
// Servo pins #define TiltPin 3 // digital pin 3, PWM pin (6V power) #define RshoulderPin 5 // digital pin 5, PWM pin (6V power) #define LshoulderPin 6 // digital pin 6, PWM pin (6V power) #define ScanPin 7 // digital pin 7 (regulated 5V power) #define PanPin 8 // digital pin 8 (regulated 5V power) #define RarmPin 9 // digital pin 9, PWM pin (6V power) #define LarmPin 10 // digital pin 10, PWM pin (6V power) #define WaistPin 11 // digital pin 11, PWM pin (6V power)
// Media pins #define speakerOut 12 // digital pin 12 #define ledPin 13 // digital pin 13
// Sensor pins #define PingPin 4 // digital pin 4 #define BattSensor 0 // analog pin 0 #define TouchPin 1 // analog pin 1 #define IR_Pin 16 // digital pin 16 (analog pin 2) #define SharpPin 3 // analog pin 3
// Moves byte Stand_By = 0; byte Rarm_Wave = 1; byte Pick_Up_Object = 2; byte Release = 3;
// Servos Servo Scan; Servo Waist; Servo Lshoulder; Servo Rshoulder; Servo Larm; Servo Rarm; Servo Pan; Servo Tilt;
// Software serial SoftwareSerial LcdSerial = SoftwareSerial(rxPin, txPin);
// Sensor Variables unsigned int PingDistance = 0; byte IrDistance = 0; byte TouchVal = 0; int temperature[] = {0,0,0,0,0,0,0,0,0}; // Array to hold temperature data
// servo variables #define center 80 byte direction = 1; byte object = 0;
//servos: stepDeleay, Waist, Lshould, Rshould, Larm, Rarm, Tilt, Pan byte oldPos[8] = {0, 70, 180, 180, 80, 90, 80, 80};
byte Speed = 0; byte Distance = 0; byte Degrees = 0; byte Object_here = 3; // object is closer than 3 byte moveNumber = 0; byte sv = 1; boolean teachMode = 0; byte pos = 80; byte index = 1; byte pos_delay = 0; boolean move = 0; boolean stored = 0; boolean state = 0;
// Play Melody variables byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956}; byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p"; // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0; int count2 = 0; int count3 = 0; int MAX_COUNT = 24;
void setup() { Wire.begin(); // join i2c bus (address optional for master)
//hardware serial Serial.begin(9600); //software serial for LCD pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); LcdSerial.begin(9600); LCDposition(1, 1); LcdSerial.print("Mini Eric"); LCDposition(2, 5); LcdSerial.print("robot"); delay(1000); //wait a second LCDclear();
//media pinMode(ledPin, OUTPUT); pinMode(speakerOut, OUTPUT);
//sensors pinMode(PingPin, OUTPUT); digitalWrite(PingPin, LOW); //servos Scan.attach(ScanPin); Pan.attach(PanPin); Tilt.attach(TiltPin); Waist.attach(WaistPin); Lshoulder.attach(LshoulderPin); Rshoulder.attach(RshoulderPin); Larm.attach(LarmPin); Rarm.attach(RarmPin);
Pan.write(center); // 0 - 80 - 170 Tilt.write(center); // 0 - 80 - 180 Scan.write(center); // 40 - 85 - 130 ; 40 = left, 130 = right Larm.write(center); // 0 - 80 - 180 Rarm.write(center+10); // 0 - 80 - 180; 0 = Lshoulder.write(center+100); // 0 - 80 - 180 Rshoulder.write(center+100); // 0 - 80 - 180 ; 0 = Up, 180 = Down Waist.write(center-10); // 70 = Up, 150 = Down
}
// Main Loop void loop(){ state = !state; digitalWrite(ledPin, state); Trigger_Wave_Hand(); //Trigger_Music(); Trigger_Pick_Object(); //Trigger_Release(); delay(1000); // delay a second to see the values Find_Hot_Object(); delay(1000); // delay a second to see the values }
int Read_Ping_Sensor() { //trigger the sensor int Ping = 0; pinMode(PingPin, OUTPUT); digitalWrite(PingPin, LOW); delayMicroseconds(2); digitalWrite(PingPin, HIGH); delayMicroseconds(5); digitalWrite(PingPin, LOW); //receive the echo pinMode(PingPin, INPUT); Ping = pulseIn(PingPin, HIGH); return Ping/29/2; // convert to cm }
int Read_Sharp_Sensor() { int value = 0; value = analogRead(SharpPin); return 509.88*pow(value,-.9154); // convert to cm }
int Read_Touch_Sensor() { int Touch=analogRead(TouchPin); return Touch; }
void Read_Thermopile_Array(){ for(int i = 0; i < 9; i++){ // Loops and stores temperature data in array temperature[i] = getTemp(i+1); } }
int getTemp(int reg){ // Function to receive one byte of data from TPA81 Wire.beginTransmission(Thermo); // Begin communication with TPA81 Wire.send(reg); // Send reg to TPA81 Wire.endTransmission(); Wire.requestFrom(Thermo, 1); // Request 1 byte while(Wire.available() < 1); // Wait for byte to arrive int data = Wire.receive(); // Get byte return(data); // return byte }
void Trigger_Wave_Hand() { PingDistance = Read_Ping_Sensor(); LCDposition(1, 1); LcdSerial.print("Ping Dist: "); LcdSerial.print(PingDistance, DEC); LcdSerial.print(" "); if (PingDistance < 40 && PingDistance > 30){ Play_Move(Rarm_Wave); } }
void Trigger_Music() { PingDistance = Read_Ping_Sensor(); LCDposition(1, 1); LcdSerial.print("Ping Dist: "); LcdSerial.print(PingDistance, DEC); LcdSerial.print(" "); if (PingDistance < 30 && PingDistance > 20) { Play_Melody(); } }
void Trigger_Pick_Object() { IrDistance = Read_Sharp_Sensor(); LCDposition(2, 1); LcdSerial.print("Sharp Dist: "); LcdSerial.print(IrDistance, DEC); LcdSerial.print(" "); if (IrDistance < Object_here){ Play_Move(Pick_Up_Object); object = 1; } }
void Trigger_Release() { PingDistance = Read_Ping_Sensor(); LCDposition(1, 1); LcdSerial.print("Ping Dist: "); LcdSerial.print(PingDistance, DEC); LcdSerial.print(" "); if (PingDistance < 20) { Play_Move(Release); object = 0; } }
void Find_Hot_Object() { Read_Thermopile_Array(); byte cluster = 0; int hotObject = temperature[0]; // ambient temperature for(byte i = 1; i < 9; i++){ if (temperature[i] > hotObject) { hotObject = temperature[i]; // store the highest temperature cluster = i; // store the location of the hottest spot } } LCDposition(1, 1); LcdSerial.print("Hot Object: "); LcdSerial.print(hotObject, DEC); LcdSerial.print(" "); LCDposition(2, 1); LcdSerial.print("in cluster "); LcdSerial.print(cluster, DEC); LcdSerial.print(" "); }
void Play_Move(byte moveNumber) { LCDposition(1, 1); LcdSerial.print("Playing "); LCDposition(2, 1); LcdSerial.print("Move "); LcdSerial.print(move, DEC); LcdSerial.print(" "); byte moveStart = EEPROM.read(490+(2*moveNumber)); byte moveEnd = EEPROM.read(491+(2*moveNumber)); for (byte i = moveStart; i <= moveEnd; i+=2){ sv = EEPROM.read(i); pos = EEPROM.read(i+1); switch (sv) { case 0: for (int u=1; u<=pos; u++){ StepDelay(); } break; case 1: Waist.write(pos); break; case 2: Lshoulder.write(pos); break; case 3: Rshoulder.write(pos); break; case 4: Larm.write(pos); break; case 5: Rarm.write(pos); break; case 6: Tilt.write(pos); break; case 7: Pan.write(pos); break; } } }
void Play_Melody() { digitalWrite(speakerOut, LOW); for (count = 0; count < MAX_COUNT; count++) { for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) { for (count2=0;count2<8;count2++) { if (names[count2] == melody[count*2 + 1]) { digitalWrite(speakerOut,HIGH); delayMicroseconds(tones[count2]); digitalWrite(speakerOut, LOW); delayMicroseconds(tones[count2]); } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size digitalWrite(speakerOut, 0); delayMicroseconds(500); } } } } }
void StepDelay() { for (int t=0; t<=10; t++){ delay(20); } }
void LCDposition (byte line, byte column) { LcdSerial.print(line, BYTE); // LCD line LcdSerial.print(column, BYTE); // LCD column }
void LCDclear () { LcdSerial.print(5, BYTE); // select LCD command mode LcdSerial.print(1, BYTE); // clear screen }
|
|
|
|
|
22
|
Forum 2005-2010 (read only) / Bugs & Suggestions / Re: MegaServo and Wire(I2C)Library conflict
|
on: September 15, 2009, 09:28:30 am
|
|
Looks like it's not only the I2C that causes servos to twitch. Below is part of the sketch I'm using. I put everything in the same sketch for easier reading (I use several tabs and libs). If you look at the main loop, you'll see some functions that do some actions based on different sensors readings. If I comment out all functions, leaving active only the state LED and delay(1000), the servos stay still. If I activate any of the functions, the servos twitch. So even reading the analog sensor or the Ping sensor create twitching. At first I was testing only the temperature array when I observed the problem. If I use the SoftwareServo library, the servos stay still, but I have to make sure I don't use delays greater than 20 ms between ServoRefresh commands.
Will it be possible to use Timer2 to set up an interrupt to issue the ServoRefresh command every 20ms? If yes, how do I set the Timer2 for that?
Thanks for your help!
|
|
|
|
|
23
|
Forum 2005-2010 (read only) / Bugs & Suggestions / Re: MegaServo and Wire(I2C)Library conflict
|
on: September 14, 2009, 11:02:39 pm
|
|
I am having the same problems here on a Roboduino board with mega168. I have 8 servos, 2 I2C sensors, one Ping sensor, one Sharp sensor. The servos are moving fantastic with the Servo library from Arduino 17, but if I enable the sensors, the servos start to move back and forth, all at once. The most weird effect is when I play a tune. The servos will move to different positions, depending on the note duration. Looks like the robot is dancing or better yet acting like it's having an epileptic episode. Everything work fine with the SoftwareServo library, but I hate that I need the refresh command and sometimes the servos don't actually go to the same angle they would if I use the new Servo library.
Question is, is it possible to fix the problem (Wire library interference)?
Thanks.
|
|
|
|
|
24
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: PID Library motor control example?
|
on: November 10, 2009, 10:16:03 pm
|
|
Yes, the Gamoto Motor controller.... Ohh, I wish I could implement these features on my motor controller in Arduino: - Serial port, at 9600, 19200 or 115200 baud; - I2C protocol as a slave device; - Trapezoidal Trajectory Profile processing (constant accel ramp, constant velocity cruise, then constant decel rampdown); - simple commands like Forward(Speed, Distance). If such a command is issued, the motor controller should accelerate to the Speed value and decelerate and stop at the specified traveled Distance. Now THAT is a motor controller! Any suggestions how to do it?
|
|
|
|
|
26
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: PROGMEM use in Arduino
|
on: November 08, 2009, 06:51:20 pm
|
Fixed the original problem by reversing the position of the PROGMEM in the declaration, like this: static const VOCAB s_vocab[] PROGMEM={...}; Now I have other errors. In the core.c file I have a struct like this: typedef struct Vocab { const char* txt; const char* phoneme; } VOCAB;
As I read about structs, I have a struct called Vocab with 2 members and an object VOCAB (I think...). Then, in the .h file I have the VOCAB declared as: static const VOCAB s_vocab[] PROGMEM={....}; However, I get this error at compile: C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's_vocab' If I add '=' like this: static const VOCAB=s_vocab[] PROGMEM={....} I get this errors: C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: 's_vocab' undeclared here (not in a function) C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: expected expression before ']' token error: 'VOCAB' redeclared as different kind of symbolC:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: previous definition of 'VOCAB' was here and it highlights the end of the struct declaration in the .c file. Any ideas how to fix this? Thank you for any help!
|
|
|
|
|
27
|
Forum 2005-2010 (read only) / Syntax & Programs / PROGMEM use in Arduino
|
on: November 08, 2009, 01:40:33 pm
|
I have a .h file with lots of entries like this: static const char v1a[] PROGMEM="OUS_"; After several entries, there is an entry like this: static const VOCAB PROGMEM s_vocab[] ={ { v1a, v1b} ,{ v2a, v2b}, { v3a, v3b},{ v4a, v4b},{ v5a, v5b},{ v6a, v6b},{ v7a, v7b},{ v8a, v8b},{ v9a, v9b},{ v10a, v10b},..... and so on.... };
Then in the code, s_vocab is used. When compiling, I get an error like this for every entry where PROGMEM is used: C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PROGMEM' Then I get this error: error: 's_vocab' undeclared (first use in this function) In function xxx I have tried to make a library, but the s_vocab gets out of scope (I don't get the PROGMEM errors in this case). Any advice would be very appreciate! Thanks!
|
|
|
|
|
28
|
Forum 2005-2010 (read only) / Interfacing / Re: grid based navigation using ultrasonic sensor
|
on: November 28, 2010, 03:07:34 pm
|
|
For mapping it is better to use a IR sensor, or better a LIDAR sensor, but they are hugely expensive. A servo with a Sharp Long Range IR sensor can become the Poor Man's Laser (PML). Another good idea is to use a compass to correct the heading. Although it is better to use a PC to do the mapping and path planning, I think it is doable on the microcontroller. A Mega has enough RAM to do it and you always can break the map into sectors and store the unused ones on a microSD card. So, to resume, you need: - encoders - compass - PML sensor or LIDAR - a microcontroller for the mapping/path planning functions - separate sensors for obstacle avoidance
The micro reads the PML scanning sensor, compass and encoders, plots the map and decides the best path to follow to get to the desired destination. Sounds easy, but there is a lot of code to do this. It will take me a long time until I'll get results, but I intend to do it. But it would be nice if someone would get there faster...
|
|
|
|
|