0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #165 on: March 11, 2012, 03:17:27 pm » |
I'm using the arduino tiny software ( http://code.google.com/p/arduino-tiny/) to try and control two servos with an ATtiny84. I have quite some timing problems as it seems to be. When I connect one servo to pin PA6 and use this software: // Based on Sweep // by BARRAGAN <http://barraganstudio.com> // This example code is in the public domain. // Changed by Johan
#include <Servo.h> Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position int posMin = 17; int posMax = 65; void setup() { myservo.attach(4); // attaches the servo on pin 4 to the servo object } void loop() { for(pos = posMin; pos < posMax; pos += 1) // goes from posMin degrees to posMax degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(3000); for(pos = posMax; pos>=posMin; pos-=1) // goes from posMax degrees to posMin degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(3000); } This works well... However, I need to control two servos. Their position should be the same so I tried to connect them to one output. This makes the servos to jiggle with no avail. I also can't seem to get the servos work on another port. I have tried using internal clock at 8Mhz and 16Mhz with an external resonator. Also capacitors. Any ideas?! Update: // Sweep // by BARRAGAN <http://barraganstudio.com> // This example code is in the public domain.
#include <Servo.h> Servo myservo1; // create servo object to control a servo Servo myservo2; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position int posMin = 17; int posMax = 65; void setup() { myservo1.attach(4); // attaches the servo on pin 9 to the servo object myservo2.attach(5); // attaches the servo on pin 9 to the servo object } void loop() { for(pos = posMin; pos < posMax; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo1.write(pos); delay(7); myservo2.write(pos); // tell servo to go to position in variable 'pos' delay(7); // waits 15ms for the servo to reach the position } delay(3000); for(pos = posMax; pos>=posMin; pos-=1) // goes from 180 degrees to 0 degrees { myservo1.write(pos); delay(7); myservo2.write(pos); // tell servo to go to position in variable 'pos' delay(7); // waits 15ms for the servo to reach the position } delay(3000); }
this also works when connecting one servo to 4 or 5 but not when I connect two servos to either port.
|
|
|
|
« Last Edit: March 11, 2012, 03:39:14 pm by jopiek »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10164
|
 |
« Reply #166 on: March 12, 2012, 02:52:05 pm » |
@jopiek: One servo on one pin works?
One servo on one pin and a second servo on a second pin works?
Two servos on on pin does not work?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10164
|
 |
« Reply #167 on: March 12, 2012, 02:56:52 pm » |
Collect verbose output from an upload attempt and post it to the forum. I get only one red line: avrdude: stk500_getsync(): not in sync: resp=0x00 If you don't get a long sign-on message from avrdude it is not in verbose mode. I'm using Arduino v0.22. Hold down the Shift key when you click upload.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #168 on: March 12, 2012, 02:58:40 pm » |
@Coding Badly:
Almost: A with one servo works (B no servo) B with one servo works (A no servo)
Problems when: 1 connecting two servos to either A or B 2 connecting servos to A and B
|
|
|
|
|
Logged
|
|
|
|
|
California
Offline
Sr. Member
Karma: 2
Posts: 409
|
 |
« Reply #169 on: March 14, 2012, 03:50:37 am » |
Do I need to do anything special to get the 85 working at 128KHz? I had to comment out serial commands and I still get this error: In file included from C:\Users\Nick\Documents\Arduino\hardware\tiny\cores\tiny\wiring.c:30: C:\Users\Nick\Documents\Arduino\hardware\tiny\cores\tiny\/core_adc.h:55:4: error: #error Add an entry for the selected processor speed. C:\Users\Nick\Documents\Arduino\hardware\tiny\cores\tiny\wiring.c: In function 'init': C:\Users\Nick\Documents\Arduino\hardware\tiny\cores\tiny\wiring.c:257: error: 'ADC_ARDUINO_PRESCALER' undeclared (first use in this function) C:\Users\Nick\Documents\Arduino\hardware\tiny\cores\tiny\wiring.c:257: error: (Each undeclared identifier is reported only once C:\Users\Nick\Documents\Arduino\hardware\tiny\cores\tiny\wiring.c:257: error: for each function it appears in.) This is my code, nothing fancy just sequencing the PWM: int list[7] = { -1,-1,-1,-1,-1,-1,-1}; byte const set[7] = { B001,B010,B011,B100,B101,B110,B000}; boolean redo = true; int x = 0; int count = 0; int count7 = 0;
int LED1 = 0; int LED2 = 1; int LED3 = 4;
int curVal[3] = { 0,0,0}; int lastVal[3] = { 0,0,0}; int nextVal[3] = { 0,0,0};
void setup(){ //Serial.begin(9600); //Serial.println("Reset"); randomSeed(analogRead(0));
pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); writeList(); for (int i = 0;i<3;i++){ nextVal[i] = (bitRead(set[list[0]],i)==1)? 255:0; } //Serial.print(list[0]); }
void loop(){ for(int i=0;i<3;i++){ curVal[i] = map(count,0,255,lastVal[i],nextVal[i]); }
analogWrite(LED1,curVal[0]); analogWrite(LED2,curVal[1]); analogWrite(LED3,curVal[2]);
if(count==255){ count = 0; if (++count7==7){ count7 = 0; //Serial.println(" "); writeList(); }
for (int i = 0;i<3;i++){ lastVal[i] = nextVal[i]; nextVal[i] = (bitRead(set[list[count7]],i)==1)? 255:0; } //delay(map(analogRead(1),0,1023,1,50) * 200); delay(200); // Serial.print(list[count7]); } count++; //delay(map(analogRead(1),0,1023,1,50)); delay(1); }
void writeList(){ int l = list[6]; for(int i = 0;i<7;i++){ list[i] = -1; } for(int i = 0;i<7;i++){ redo = true; while(redo){ x=random(7); if(list[x]==-1){ redo=false; list[x] = i; } } } if(list[0]==l){ int y = random(1,7); x= list[y]; list[y] = list[0]; list[0] = x; } }
It works fine on any of the other attiny85 settings thanks
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10164
|
 |
« Reply #170 on: March 14, 2012, 04:16:41 pm » |
Do I need to do anything special to get the 85 working at 128KHz? Huh. I don't remember why I added that board option. I know I didn't test it. Oh well. • Open core_build_options.h • Change INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER from 1 to zero. The are of interest is... http://code.google.com/p/arduino-tiny/source/browse/trunk/hardware/tiny/cores/tiny/core_build_options.h#28• Save and close core_build_options.h Bear in mind that analogRead will no longer be available.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 64
|
 |
« Reply #171 on: March 25, 2012, 05:44:54 am » |
Hello, I am trying to compile a small test sketch for Attiny4313 using latest core and Arduino 1.0 IDE. The sketch below compiles for Attiny2313, compiling under Attiny4313 throws an error: unknown MCU 'attiny4313' specified Known MCU names: avr2 at90s2313 at90s2323 at90s2333 ... Is attiny4313 recognized in the (older) version of WinAVR included with ARDUINO 1.0, or am I doing something wrong? Thanks, George /* Attiny4313 example (G.Small, 24Mar2012) Example of Attiny4313 on Arduino Tiny core, with serial comms test
ATMEL 6 PIN ISP CONNECTOR TOP VIEW: +---+ MISO 1 |o o| 2 +Vcc (SCL, to UNO A5) SCK 3 |o o| 4 MOSI (SDA, to UNO A4) /RESET 5 |o o| 6 GND +---+
ATMEL AttinyX313/ARDUINO:
+-\/-+ (D 17) PA2 1| |29 VCC RX (D 0) PD0 2| |19 PB7 (D 16) TX (D 1) PD1 3| |18 PB6 (D 15) (D 2) PA1 4| |17 PB5 (D 14) (D 3) PA0 5| |16 PB4 (D 13)* INT0 (D 4) PD2 6| |15 PB3 (D 12)* INT1 (D 5) PD3 7| |14 PB2 (D 11)* (D 6) PD4 8| |13 PB1 (D 10) *(D 7) PD5 9| |12 PB0 (D 9) GND 10| |11 PD6 (D 8) +----+
* indicates PWM port
These arrays map port names (e.g. port B) to the appropriate addresses for various functions (e.g. reading and writing)
*/
#define LED_PIN 6 // ATtiny Pin 8 (D6)
void setup(){ pinMode(LED_PIN,OUTPUT); // for general DEBUG use LED_Blink(LED_PIN,2); // show it's alive Serial.begin(9600); }
void loop() { int test = 31; Serial.print("test"); LED_Blink(LED_PIN,1); // show it's alive }
// LED blinker for status void LED_Blink(byte pin, byte times){ for (byte i=0; i< times; i++){ digitalWrite(pin,LOW); delay (1000); digitalWrite(pin,HIGH); delay (1000); } }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10164
|
 |
« Reply #172 on: March 25, 2012, 01:49:39 pm » |
Is attiny4313 recognized in the (older) version of WinAVR included with ARDUINO 1.0, No. or am I doing something wrong? Nope. Compiles just fine. There are instructions in the forum for upgrading to the latest version of WinAVR. If you can't find them, let me know.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 64
|
 |
« Reply #173 on: March 25, 2012, 08:05:53 pm » |
There are instructions in the forum for upgrading to the latest version of WinAVR. If you can't find them, let me know.
Thanks once again for the help. I updated my Arduino WinAVR. I had to copy over avrdude.exe 5.11 and avrdude.conf from Arduino 1.0 folder to get my Pololu AVR USB Programmer to work but everything is now functional! Thanks, George
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #174 on: April 16, 2012, 03:29:32 pm » |
- delay() seems not to work on Tiny85 at 8Mhz (int. osc.). (might be Proteus simulation bug, but it works ok with HLT core). By default, the Tiny Core uses timer 1 for millis on the ATtiny85 processor whereas the HLT core uses timer 0. Timer 1 on the ATtiny85 is unique in the AVR world. I suspect Proteus does not simulate the timer correctly. I finally tried on real hardware, yes, delay() works ok, that's really a Proteus bug. I've tried running both options - 8 MHz and 16 Mhz PLL - blink works ok on both, timing is correct. But I ran into problem with Serial (one-way-tx-only). At 8 MHz it works ok. I even successfully ran TinyTuner. But at 16 Mhz PLL it doesn't work. Even at 9600 bps nothing is transmitted. I use IDE v.1.0 and tiny core ver. 0012. What do you think could be wrong? An one more question: the guys mentioned a "modded" NewSoftSerial, could you give a hint where to find it? One
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10164
|
 |
« Reply #175 on: April 16, 2012, 04:49:37 pm » |
I finally tried on real hardware, yes, delay() works ok, that's really a Proteus bug. Excellent. (that it works not that Proteus has a bug) I've tried running both options - 8 MHz and 16 Mhz PLL - blink works ok on both, timing is correct. More good news. Nice! But I ran into problem with Serial (one-way-tx-only). The stuff that comes with the Tiny Core? Tiny Debug Serial? At 8 MHz it works ok. I even successfully ran TinyTuner. But at 16 Mhz PLL it doesn't work. Even at 9600 bps nothing is transmitted. #if F_CPU <= 8000000L // port B bit 3 (PB3) #define TINY_DEBUG_SERIAL_REGISTER 0x18 #define TINY_DEBUG_SERIAL_BIT 3 #else // port B bit 2 (PB2) #define TINY_DEBUG_SERIAL_REGISTER 0x18 #define TINY_DEBUG_SERIAL_BIT 2 #endif A different pin is used at 16 MHz. I assumed that a crystal or resonator would be connected. You can either adjust the code above (in TinyDebugSerial.h) or use the alternate pin. An one more question: the guys mentioned a "modded" NewSoftSerial, could you give a hint where to find it? There was a discussion here in the forum. Try searching. If you can't find it, report back and I'll make an attempt.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #176 on: April 17, 2012, 02:07:57 pm » |
You can either adjust the code above (in TinyDebugSerial.h) or use the alternate pin. Thank you. I preferred to edited the file. After OSCCAL adjustment it works perfectly, even at 115200 bps.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #177 on: April 22, 2012, 02:54:18 am » |
Dear Coding BadlyI've now run into another problem. After studying the Attiny85 datasheet I'm tryin to utilize timer1 for precise pulse control. I freed timer1 by modifying wiring.c (as you wrote earlier). My intent is to be able to set precise pause length and pulse length of aech indiviual pulse. I use following setup: void setup() { pinMode(4,OUTPUT); //needed for OC1B digitalWrite(4,LOW); pinMode(3,OUTPUT); //needed for myself digitalWrite(3,LOW);
TCCR1 = 0b1000; // clock ck/128 GTCCR = (1<<PWM1B) | (1<<COM1B1) | (1<<COM1B0) ; // <<PROBLEM HERE OCR1B = 41; OCR1C = 100; } I need the pin to go low on OCR1C compare match and then go high on OCR1B compare match. So according to above code I should get a pause of 41 ticks and then a pulse of 59 ticks and so on. But something goes wrong. I get only a constant HIGH state on pin4. I tried to use (1<<COM1B1) | (0<<COM1B0) instead, and it works ok (!), but the signal gets actually inverted, that's not what I need. (0<<COM1B1) | (1<<COM1B0) also works ok, I get signal on two pins and one of them (pin 3) is "inverted inverted", thus suitable for me, but that wastes one pin (pin4), which I need to use as I/O, so that's not ok for me also. Could you give a hint?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10164
|
 |
« Reply #178 on: April 22, 2012, 03:26:06 am » |
I'll try to look more closely at it tomorrow but I believe you have to set CTC1 in TCCR1... TCCR1 = (1 << CTC1) | (0 << PWM1A) | (0 << COM1A1) | (0 << COM1A0) | (1 << CS13) | (0 << CS12) | (0 << CS11) | (0 << CS10);
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #179 on: April 22, 2012, 06:44:14 am » |
The datasheet says that in PWM mode the counter is reset on OCR1C compare match regardless of CTC1 bit state. Anyway I already tried setting CTC1, that didn't help.
|
|
|
|
|
Logged
|
|
|
|
|
|