Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Project Guidance / Re: PS2 Controller Hookup on: April 24, 2012, 05:57:06 pm
Here is the actual code:

Code:
// This program compiles the Playstation controller button statuses into a 6 byte string.
// The first 2 bytes contain button status and the last 4 contain the thumbstick positions.
// by Adam Kemp, 2012 http://code.google.com/p/smduino/

#include <PS2X_lib.h>  //for v1.6 (Thanks to Bill Porter for a wicked library http://www.billporter.info/playstation-2-controller-arduino-library-v1-0/)

PS2X ps2x; // create PS2 Controller Class

int battLow = 801;  //Batt low value determined from 22k/100k voltage divider. Represents ~3.3V
boolean lowBattWarning = false; //flag for a low battery condition
boolean ledState = false; //used for flashing LED during a low power condition
unsigned long currentTime = 0;

void setup(){
 Serial.begin(57600);
  pinMode(13, OUTPUT);
  for (int i = 0; i < 4; i++) { //check status LED
    digitalWrite(13, LOW);
    delay(50);
    digitalWrite(13, HIGH);
    delay(50);
  }
  digitalWrite(13, HIGH);
  ps2x.config_gamepad(3,5,6,4, false, false);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
}

void loop(){
  byte buttons = 0;
  byte dPads = 0;
  ps2x.read_gamepad();
  bitWrite(buttons, 0, ps2x.Button(PSB_SELECT)); //byte 1, bit 0
  bitWrite(buttons, 1, ps2x.Button(PSB_START)); //byte , bit 1
  bitWrite(buttons, 2, ps2x.Button(PSB_L1)); //byte 1, bit 2
  bitWrite(buttons, 3, ps2x.Button(PSB_R1)); //byte 1, bit 3
  bitWrite(buttons, 4, ps2x.Button(PSB_L2)); //byte 1, bit 4
  bitWrite(buttons, 5, ps2x.Button(PSB_R2)); //byte 1, bit 5
  bitWrite(buttons, 6, ps2x.Button(PSB_L3)); //byte 1, bit 6
  bitWrite(buttons, 7, ps2x.Button(PSB_R3)); //byte 1, bit 7
  bitWrite(dPads, 0, ps2x.Button(PSB_PAD_UP)); //byte 2, bit 0
  bitWrite(dPads, 1, ps2x.Button(PSB_PAD_DOWN)); //byte 2, bit 1
  bitWrite(dPads, 2, ps2x.Button(PSB_PAD_LEFT)); //byte 2, bit 2
  bitWrite(dPads, 3, ps2x.Button(PSB_PAD_RIGHT)); //byte 2, bit 3
  bitWrite(dPads, 4, ps2x.Button(PSB_GREEN)); //byte 2, bit 4
  bitWrite(dPads, 5, ps2x.Button(PSB_BLUE)); //byte 2, bit 5
  bitWrite(dPads, 6, ps2x.Button(PSB_PINK)); //byte 2, bit 6
  bitWrite(dPads, 7, ps2x.Button(PSB_RED)); //byte 2, bit 7
  Serial.print(buttons); //prints byte 1
  Serial.print(dPads); //prints byte 2
  Serial.print(ps2x.Analog(PSS_LY)); //prints left y thumbstick value
  Serial.print(ps2x.Analog(PSS_LX)); //prints left x thumbstick value
  Serial.print(ps2x.Analog(PSS_RY)); //prints right y thumbstick value
  Serial.print(ps2x.Analog(PSS_RX)); //prints right x thumbstick value
  byte battStat = map(analogRead(0), 801, 1024, 0, 100); //reads batt voltage and calculates a percentage. 3.3v = 0%
  if (battStat <= 10) { //not tested, but checks if the battery is below 10%
    lowBattWarning = true;
  }
  if (lowBattWarning) { //if battery is below 10% start flashing the LED
    if (millis() > currentTime + 1000) {
      currentTime = millis();
      digitalWrite(13, !ledState);
    }
  }
 delay(100); //rinse, wash, repeat
}
2  Using Arduino / Project Guidance / PS2 Controller Hookup on: April 24, 2012, 04:59:37 pm
I recently saw this post on the adafruit site and thought I would give it a go.
http://www.adafruit.com/blog/2012/04/23/weekend-project-arduino-xbee-ps2-controller-20-channel-universal-project-controller/comment-page-1/#comment-32983
I am using an original dual shock playstation 2 wired controller and an arduino duemilanove.

The original article is here: http://code.google.com/p/smduino/wiki/PlaystationControl

The source for that code is here: http://store.curiousinventor.com/guides/PS2/#hardware

I have connected the PS2 wires to the arduino as shown in the code but all I get from terminal is "yy yy yy yy yy yy..."

I definitely have power to the controller because the indicator LED lights up when I push the analog button.

here is a pic of the wires:


here is the schematic: http://smduino.googlecode.com/files/SMDuino%20-%20Playstation%20Control.pdf

In the code it states which wires go to which arduino pins:

Code:
ps2x.config_gamepad(3,5,6,4, false, false);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

I have wired all the PS2 wires according to the color label chart and the instructions in the code but I am still getting "yy yy yy yy..." in terminal.

I have even tried using level shifting resistors incase the controller needs a 3 volt supply, but it didn't change anything

I have also already changed the baud rate in terminal to 57600 because the code initializes serial at 57600

Does anyone have ideas on what to do? I'm stuck.
 
3  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 13, 2012, 05:52:45 pm
Wow amazing job Nick! That's wonderful. You're right about the memory being a problem, but at least we know it is possible for an attiny85 to recognize an IR signal.
4  Using Arduino / Microcontrollers / Re: Attiny 85 IR problems on: February 12, 2012, 03:05:13 pm
I have tried a 16mhz external crystal (as the original code was written for the 328 arduino board, but I get the same unresponsiveness. I have also tried setting the internal fuses to the 8mhz setting but it seems not to help in any way.
5  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 10:11:46 pm
The most obvious difference for the tv b gone is that it uses an external 8mhz resonator to get accurate timing. If that were the problem though, wouldn't I be getting at least inaccurate readings and outputs? I'm still learning my way around comparatively simple sketches, but the tv b gone seems to go about sending IR signals differently than the project I am trying to adapt.
6  Using Arduino / Microcontrollers / Attiny 85 IR problems on: February 11, 2012, 09:16:44 pm
I have been working on adapting this code for a while. I am adapting this code: http://arcfn.com/files/IRremote.zip  To work on an attiny85. I have changed all the timers in the code to timer 0 to be compatible with the attiny. See the thread here: http://arduino.cc/forum/index.php/topic,91488.0.html

I have also found a specific attiny85 core for uploading the code with software serial. See thread: http://arduino.cc/forum/index.php/topic,91174.0.html

I have finally got the code to load onto the attiny85. However, once the code is loaded, the circuit for the attiny will not recognize or output any IR signals.

here is the original project I am converting to attiny85 http://www.arcfn.com/2009/09/arduino-universal-remote-record-and.html

I have tested all the components separately.

I have tested all the attiny pins separately

I am using a duemilanove as and ISP programmer

Please help! It took so long to get the code loaded! Now I am totally stumped!

Thanks,

Will
7  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 07:54:09 pm
Code now loads fine after a few seconds. The circuit is totally unresponsive though. It doesn't register any IR signals, status or IR output. I have tested each pin with an LED using the example Blink sketch and they all work fine.
8  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 07:37:44 pm
For reference, this is the project I am trying to load to the attiny85: http://www.arcfn.com/2009/09/arduino-universal-remote-record-and.html
I have seen elsewhere that this last error is to be expected when loading sketches to the attiny85 but should not interfere with anything. In any case, I have changed the status pin to pin 4 with a red LED. I have changed the receive pin to pin 1. I have changed the button pin to pin 0. The output signal is sent to the IR LED through pin 3 in the original code so I have attached the IR led here to pin 3 on the attiny85.

I am using an arduino board as and ISP programmer connected to my attiny85 on a breadboard.
When I load the sketch, the tx and rx leds on the arduino board keep blinking long after the sketch is loaded. The led on the arduino board attached to pin 13 also flashes along with the tx and rx leds. After a few seconds of this they all stop and do not come back on. Neither the IR led nor the status led on the breadboard connected to the attiny light up at all. The circuit also does not appear to receive any IR signals directed at the IR receiver.
9  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 07:07:03 pm
If I keep the output labeled status on pin 13 and change the recieve input to 0 and the button input to 1 I get this error:

Code:
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
10  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 07:00:35 pm
Ok it now compiles! However, I now get this error when attempting to load the sketch onto the attiny85:

Code:
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: verification error, first mismatch at byte 0x03d3
         0xd1 != 0xff
avrdude: verification error; content mismatch
11  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 06:27:11 pm
Thank you so much Nick! It compiled! I will test the circuit and report back!
12  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 05:44:46 pm
correction: there is no TCNT at all in the .cpp file
13  Using Arduino / Programming Questions / Re: Help Change timer 2 to timer 0 on: February 11, 2012, 05:39:11 pm
Thanks Nick! I have changed the TIMSK0's to TIMSK but i am still getting this error message:

Code:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRrecv::enableIRIn()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: ‘TCNT2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function ‘void TIMER2_OVF_vect()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: ‘TCNT2’ was not declared in this scope

and yet when I search the .cpp file there is no 'TCNT2'

I had changed these to TCNT0. Need I go back and delete all of the zeros inserted at the beginning?

Thank you so much again!
14  Using Arduino / Programming Questions / Help Change timer 2 to timer 0 on: February 11, 2012, 04:04:17 pm
I am attempting to change this code from using timer 2 to using timer 0 so I can use it with an attiny85 that does not have timer 2.

Here is a link to the zip file containing the code: http://arcfn.com/files/IRremote.zip

I am modifying the .cpp file

When I first tried to upload this without having changed the timer I got this error:
Code:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::mark(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:172:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:172:13: error: ‘COM2B1’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::space(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:180:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:180:15: error: ‘COM2B1’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::enableIROut(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:3: error: ‘TIMSK2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:14: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:12: error: ‘WGM20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:3: error: ‘TCCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:12: error: ‘WGM22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:25: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:211:3: error: ‘OCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:212:3: error: ‘OCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRrecv::enableIRIn()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:224:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: ‘TCCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: ‘CS22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:230:3: error: ‘CS21’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:231:3: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TIMSK2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: ‘TCNT2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function ‘void TIMER2_OVF_vect()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: ‘TCNT2’ was not declared in this scope

I went through the .cpp file and changed each one of the parts mentioned so that the 2s became 0s. Having done that I am still getting this error message:
Code:

/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::enableIROut(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:3: error: ‘TIMSK0’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRrecv::enableIRIn()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TIMSK0’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: ‘TCNT2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function ‘void TIMER2_OVF_vect()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: ‘TCNT2’ was not declared in this scope

I don't understand! Please help.

Thanks,
Will
15  Using Arduino / Programming Questions / Re: IR Code on Attiny gives error on: February 10, 2012, 05:31:52 pm
ok, here is a list of the parts I have guessed need changing. If any of these is not part of the register or bit references please point it out:
again you can get the .cpp file i am trying to fix from this zip file: http://arcfn.com/files/IRremote.zip

Code:
void IRsend::mark(int time) {
  // Sends an IR mark for the specified number of microseconds.
  // The mark output is modulated at the PWM frequency.
  TCCR2A |= _BV(COM2B1); // Enable pin 3 PWM output
  delayMicroseconds(time);
I changed only TCCR2A to TCCR0A here


Code:
/* Leave pin off for time (given in microseconds) */
void IRsend::space(int time) {
  // Sends an IR space for the specified number of microseconds.
  // A space is no output, so the PWM output is disabled.
  TCCR2A &= ~(_BV(COM2B1)); // Disable pin 3 PWM output
  delayMicroseconds(time);
I changed only TCCR2A to TCCR0A here

Code:
// Disable the Timer2 Interrupt (which is used for receiving IR)
  TIMSK2 &= ~_BV(TOIE2); //Timer2 Overflow Interrupt
I only changed TIMSK2 to TIMSK0 here

Code:
// COM2A = 00: disconnect OC2A
  // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
  // WGM2 = 101: phase-correct PWM with OCRA as top
  // CS2 = 000: no prescaling
  TCCR2A = _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS20);
I changed TCCR2A to TCCR0A and TCCR2B to TCCR0B

Code:
// The top value for the timer.  The modulation frequency will be SYSCLOCK / 2 / OCR2A.
  OCR2A = SYSCLOCK / 2 / khz / 1000;
  OCR2B = OCR2A / 3; // 33% duty cycle
I changed both 'OCR2A's to OCR0A and OCR2B to OCR0B

Code:
// setup pulse clock timer interrupt
  TCCR2A = 0;  // normal mode
I changed TCCR2A to TCCR0A

Code:
//Prescale /8 (16M/8 = 0.5 microseconds per tick)
  // Therefore, the timer interval can range from 0.5 to 128 microseconds
  // depending on the reset value (255 to 0)
  cbi(TCCR2B,CS22);
  sbi(TCCR2B,CS21);
  cbi(TCCR2B,CS20);
I changed only the 'TCCR2B's to TCCR0B

Code:
//Timer2 Overflow Interrupt Enable
  sbi(TIMSK2,TOIE2);

  RESET_TIMER2;
I changed TIMSK2 to TIMSK0 and RESET_TIMER2 to RESET_TIMER0

Code:
ISR(TIMER2_OVF_vect)
{
  RESET_TIMER2;
I changed both 'TIMER2's to TIMER0

After doing all of this I Attempted to compile for the attiny85 and got this error:

Code:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::mark(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:172:13: error: ‘COM2B1’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::space(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:180:15: error: ‘COM2B1’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::enableIROut(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:3: error: ‘TIMSK0’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:14: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:12: error: ‘WGM20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:12: error: ‘WGM22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:25: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRrecv::enableIRIn()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: ‘CS22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:230:3: error: ‘CS21’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:231:3: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TIMSK2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: ‘TCNT2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function ‘void __vector_5()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: ‘RESET_TIMER0’ was not declared in this scope
Pages: [1] 2 3 ... 5