Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Microcontrollers / analogRead function in ATtiny chip on: January 12, 2012, 01:24:03 pm
Hi,

When using this code in my Arduino ATmega it works fine and the moment of engagement can be trimmed with a potmeter.

Code:
/*
code to use 2 leds as brake lights on RC car
If the esc/throttle servo has to be trimmed
the pot meter can be used to set the moment
of engagement to the desired value
by Leo Groeneveld, dec 2011
*/

const int ledPin = 0;

int ledState = LOW;
int x;                          // variable to store trigger value
int y;                          // variable to store pulse width

void setup()
{
pinMode(1, INPUT);              // Pin 1 (3) set as input to read the PPM signal from RC receiver for the UNO use the number between parentheses
pinMode(2, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState); // turn/keep leds off at start
}

void loop()
{
int sensorValue = analogRead(2);      // Read value from resistor
x = map (sensorValue, 0, 1023, 1000, 1500);
y = pulseIn(1, HIGH);

if(y < x && ledState == LOW){
  ledState = HIGH;
  digitalWrite(ledPin, ledState);
}
  else
    if(y > x && ledState == HIGH){
      ledState = LOW;
      digitalWrite(ledPin, ledState);
    }
}

When using the same code in an ATtiny45 the potmeter does nothing.
The ATtiny should be able to do an analogRead on pin 2 but it doesn't.

Should the code be changed for an ATtiny?

EDIT: solved by using pin 3, but pin 2 should be able to work also according to this image:


2  Using Arduino / Microcontrollers / Re: blinking brake lights for RC cars not working in ATtiny45 on: January 12, 2012, 01:07:57 pm
Hi,

It should be 8MHz because I "burned" the bootloader.

3  Using Arduino / Microcontrollers / blinking brake lights for RC cars not working in ATtiny45 on: January 11, 2012, 05:54:26 pm
Hi,

I have made a code for blinking brake lights.

The code works fine with my ATmega1280 as can be seen here:


When I upload the code in an ATtiny45 it doesn't work. When the transmitter is off the led slowly blinks and when I turn the transmitter on the led just fades and does nothing.
When the transmitter is turned on again the led starts blinking slowly again.

Here's the code:
Code:

const int ledPin = 0;                      // number of the LED pin

int ledState = LOW;
int t;
int x;
int y;
int z;

long previousMillis = 0;                     // will store last time LED was updated

                                             // the follow variables is a long because the time, measured in miliseconds,
                                             // will quickly become a bigger number than can be stored in an int.
long interval = 100;                         // interval at which to blink (milliseconds)

void setup() {
  pinMode(ledPin, OUTPUT);                   // set the digital pin as output:
  t = 0;
  z = 1400;
}

void loop()
{
  y = pulseIn(1, HIGH);                      // read PPM signal on ch.2 from receiver
    if(y > z){
      x = 1;
    }
    else
    if(y <= z){
      x = 0;
    }

unsigned long currentMillis = millis();
 
 if(x == 0 && t == 0){
   previousMillis = currentMillis;
   ledState = HIGH;
   digitalWrite(ledPin, ledState);
   t = 1;
 }
 
if(x == 0 && t == 1 && currentMillis - previousMillis > interval && ledState == HIGH){
  previousMillis = currentMillis;
  ledState = LOW;
  digitalWrite(ledPin, ledState);
}

if(x == 0 && t == 1 && currentMillis - previousMillis > interval && ledState == LOW){
  previousMillis = currentMillis;
  ledState = HIGH;
  digitalWrite(ledPin, ledState);
}

if(x == 1 && t == 1){
  t = 0;
  if(ledState == HIGH){
    ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}
}

What am I doing wrong?

Leo
4  Using Arduino / Microcontrollers / Re: problem programming Attiny85 with UNO on: December 26, 2011, 04:16:54 am
I've made this configuration with a couple of resistors to get exactly 120 ohms.


Now I get this error message after the Rx led on the Uno flashes three times:


This is the orientation of the ATTiny in the bread board wrt it's connections.


(I previously bent the legs of the cap for a better fit in the bread board but no results there)

(I'm going to clear everything today to put an extra lamp on the ceiling tomorrow)

EDIT:

It's working now!!!

I made the rookie mistake of not connecting the ground of the chip after I used the ground lead for the resistors and I left the cap and resistors out and now it works.
So the auto reset is not disabled. I also connected a led to pin 9 to see the heartbeat.

Thanks guys for the support.

Here a short vid of the result.
Brake lights for my Team Associated SC10 short course race truck.
(you cannot see it clear on the vid but the leds burn when the brake is engaged, with the potmeter I can tune the moment of engagement to follow trim of the ESC if necessary)



5  Using Arduino / Microcontrollers / Re: problem programming Attiny85 with UNO on: December 26, 2011, 03:27:20 am
I have to check pin 9 with a led.

I used a 10 uF from an old VCR so it might be faulty or the legs are too short to use in the bread board. New ones are on their way.

I will put a led on pin 9 and try a resistor.

(I bought a clone Uno so I don't know what bootloader is on the Uno itself)

I'm going to try again, I'm new at this so my stock of resistors is limited but I will try.
6  Using Arduino / Microcontrollers / Re: problem programming Attiny85 with UNO on: December 26, 2011, 12:04:23 am
That's great!

Over here no succes yet.

Instead of that I get this:
After Burning Bootloader to ATtiny45

This should be ok.
And then it happened:
After trying to upload the sketch to the ATtiny


What went wrong?
7  Using Arduino / Microcontrollers / Re: When will the new code be available to use an UNO as an ISP? on: December 22, 2011, 11:23:39 pm
could you have a look to this thread?
http://arduino.cc/forum/index.php/topic,84095.0.html
Yikes!  Sounds like the ISP gods are very unhappy with you  smiley-roll-blue

I'm afraid that I cannot offer any advice.  I can only say again that my Uno board no longer requires that autoreset be disabled when programming with ArduinoISP.  Before I flashed the chip with the new version of optiboot, my Uno board would not work without physically disabling autoreset.  I have only used ArduinoISP to program ATmega328P chips, though.

Jim

Hi Jim,

Where can we find the latest version of optiboot and how to flash it to the Uno board?

(I'm going to try with my board as is because I have just bought it so it might be new but just in case it's an old one)

8  Using Arduino / Microcontrollers / Re: When will the new code be available to use an UNO as an ISP? on: December 21, 2011, 02:53:38 pm
Ok, that's good to read.

Thanks!
9  Using Arduino / Microcontrollers / When will the new code be available to use an UNO as an ISP? on: December 21, 2011, 02:42:37 pm
3 weeks ago I bought an Arduino UNO to use as an ISP board.

Now I read this on the Arduino site.

"NOTE: Currently, you cannot use an Arduino Uno as an ISP programmer because the optiboot bootloader does not support this sketch. A revision for this is in progress."

Because no target is mentioned I wonder when the new revision will be ready, I'm almost ready to start programming some Attiny chips, just waiting for some capacitors to arrive.

10  Using Arduino / Sensors / Re: how to read PWM signal from RC receiver on: December 03, 2011, 04:53:39 pm
Quote
The receiver makes a PWM signal for each channel (receiver output to esc, servo's and my attiny) from the PPM signal (receiver input).
Servos typically use PPM as their input, as do ESCs.
It simplifies the decoder in the receiver.
Your setup may be an exception.

http://www.brookshiresoftware.com/rd_how_servos_work.htm

Now I'm lost.

I have audio tester, maybe I'll measure it next week and know for sure.
11  Using Arduino / Sensors / Re: how to read PWM signal from RC receiver on: December 03, 2011, 12:04:40 pm
@John,

Thanks for the micros function, but what if my second PWM changes while the interrupt on the other pins is executed?
(is it possible to monitor 2 PWM signals simultaneously with one attiny)

@AWOL,

I will look into it but I think PPM is the signal type used between the transmitter and receiver.

The receiver makes a PWM signal for each channel (receiver output to esc, servo's and my attiny) from the PPM signal (receiver input).
I'm 99% sure about this.
12  Using Arduino / Sensors / Re: how to read PWM signal from RC receiver on: December 03, 2011, 10:42:01 am
Thanks,

I'm afraid I cannot use PulseIn as it waits for the end of the pulse and I want to run 2 processes at the time (read out 2 channels from the receiver).

There is a function called millis which would be perfect if it would be in microseconds.
Is there a way to measure time in the background in microseconds?

Thanks
13  Using Arduino / Sensors / how to read PWM signal from RC receiver on: November 21, 2011, 03:25:08 pm
Hi,

I would like to use PWM signals from my RC car receiver to steer some leds.

I would like to activate brake lights when the car is braking and flash a set of head lights for x times when I push the button on the 3rd channel. (like used at le mans when a prototype is getting close to a slower vehicle)
Also the voltage from the LiPo should be monitored and when it droppes below 6,6V a bright red led should be turned on in the cockpit. There are IC's readily available which switch at a certain voltage, I just have to look for them to make an input signal for the chip.

I intend to use a tiny45 chip and wonder how the chip can read the PWM signals from the receiver.

Can the chip "read" the PWM signal and know the pulse width or should I make an RC network to make an analog input and map it?

Thanks

14  Using Arduino / Sensors / ... on: March 06, 2011, 08:49:49 am
...
15  Using Arduino / Sensors / trouble reading rotary encoder on: February 16, 2011, 12:02:48 pm
Hi,

I have received 2 318-ENC130175F-12PS rotary encoders yesterday and have been playing with them all day today, or at least tried to play with them.

I'm using this code, from the Arduino site, and nothing happens.

Code:
#define encoder0PinA 2
#define encoder0PinB 3

volatile unsigned int encoder0Pos = 0;

void setup() {
  pinMode(encoder0PinA, INPUT);
  pinMode(encoder0PinB, INPUT);
  attachInterrupt(0, doEncoderA, CHANGE);  // encoder pin on interrupt 0 (pin 2)
  attachInterrupt(1, doEncoderB, CHANGE);  // encoder pin on interrupt 1 (pin 3)
  Serial.begin (9600);
  Serial.println ("start reading encoder");
  Serial.println (encoder0Pos, DEC);
}

void loop(){ //Do stuff here
}

void doEncoderA(){
  if (digitalRead(encoder0PinA) == HIGH) {   // look for a low-to-high on channel A
    if (digitalRead(encoder0PinB) == LOW) {  // check channel B to see which way encoder is turning
      encoder0Pos = encoder0Pos + 1;         // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
  }
  else                                       // must be a high-to-low edge on channel A                                       
  {
    if (digitalRead(encoder0PinB) == HIGH) { // check channel B to see which way encoder is turning 
      encoder0Pos = encoder0Pos + 1;         // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
  }
  Serial.println (encoder0Pos, DEC);         // use for debugging - remember to comment out
}

void doEncoderB(){
  if (digitalRead(encoder0PinB) == HIGH) {   // look for a low-to-high on channel B
    if (digitalRead(encoder0PinA) == HIGH) { // check channel A to see which way encoder is turning
      encoder0Pos = encoder0Pos + 1;         // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
  }
  else {                                      // Look for a high-to-low on channel B
    if (digitalRead(encoder0PinA) == LOW) {   // check channel B to see which way encoder is turning 
      encoder0Pos = encoder0Pos + 1;          // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;          // CCW
    }
  }
  Serial.println (encoder0Pos, DEC);         // use for debugging - remember to comment out
}

Should I use resistors between the encoder and the pins?
Are the pins analog or digital pins?

There are no images showing how to connect stuff in the playground.

as I rotate the encoder and the serial monitor is started nothing happens.

Did I break my Arduino not using resistors and shorting the pins to 5V? (I have tested all used pins as inputs and they still seem to work fine)

Pages: [1] 2 3 4