Analog pin A3 & A1 is not working at the same time

I can send analog code through IR individually. but when I try to send xpin & ypin value at the same time it does not work. please help me to find out the problem. Any help will be appreciable. Thank you

#include <attiny85_ir_send.h>
//#include <avr/io.h>
//#include <avr/delay.h>
IRsend irsend;

int xPin = A3;
int yPin = A1;
const int ledPin = 1;

int xPosition = 0;
int yPosition = 0;
//int buttonState = 0;

void setup() {
// initialize serial communications at 9600 bps:
// Serial.begin(9600);

pinMode(xPin, INPUT);
pinMode(yPin, INPUT);

//activate pull-up resistor on the push-button pin
pinMode(ledPin, OUTPUT);

// For versions prior to Arduino 1.0.1
// pinMode(buttonPin, INPUT);
// digitalWrite(buttonPin, HIGH);

}

void loop() {
xPosition = analogRead(xPin)/4;
yPosition = analogRead(yPin)/4;
//buttonState = digitalRead(buttonPin);

// Serial.print("X: “);
// Serial.print(xPosition);
// Serial.print(” | Y: “);
//Serial.print(yPosition);
// Serial.print(” | Button: ");
// Serial.println(buttonState);
if( yPosition>20 && yPosition<70 && xPosition>150){
irsend.sendNEC(0x40BDC837ul, 32); // left + forward
// delay(50);
}
else if(yPosition>20 && yPosition<70 && xPosition<100){
irsend.sendNEC(0x40BD48B7ul, 32); // right + froword
// delay(50);
}
else if(yPosition>71 && xPosition<100){
irsend.sendNEC(0x40BD8877ul, 32); // right +forward2
//delay(50);
}
else if(yPosition>71 && xPosition>150){
irsend.sendNEC(0x40BD08F7ul, 32); // left + forward2
// delay(50);
}

else if(yPosition>71){
irsend.sendNEC(0x3967FD0D, 32); // forward2
// delay(50);
}
else if(yPosition>20 && yPosition<70){
irsend.sendNEC(0xC9DC4F09, 32); // forward
// delay(50);
}
else if(xPosition<100){
irsend.sendNEC(0xF2F28D71, 32); // right
// delay(50);
}
else if(xPosition>150){
irsend.sendNEC(0x422EBE6D, 32); // left
// delay(50);
}
delay(50);
}

// delay(100); // add some delay between reads

forward2 and forward are never executed
Do you want that?

I have modified your sketch to make that more obvious.

if (yPosition>20 && yPosition<70)
{
	if (xPosition>150) 
	{
		irsend.sendNEC(0x40BDC837ul, 32); // left + forward
	}
  	else if (xPosition<100)
  	{
		irsend.sendNEC(0x40BD48B7ul, 32); // right + froword
	}
}
else if(yPosition>71)
{
 	if (xPosition<100)
 	{
		irsend.sendNEC(0x40BD8877ul, 32); // right +forward2
  	}
  	else if(xPosition>150)
  	{
		irsend.sendNEC(0x40BD08F7ul, 32); // left + forward2
  	}
}
else if(yPosition>71)
{ 
		irsend.sendNEC(0x3967FD0D, 32); //  forward2
}
else if(yPosition>20 && yPosition<70)
{
		irsend.sendNEC(0xC9DC4F09, 32); // forward
}
else if(xPosition<100)
{
		irsend.sendNEC(0xF2F28D71, 32); // right 
}
else if(xPosition>150)
{
		irsend.sendNEC(0x422EBE6D, 32); // left
}

Hi ieee488,
At First I want to thank you for your help. Every statements work fine except only forward and forward2 does not work. I mean left+forward, left+forward2, right+forward, right+forward2, left, right commands work. I would be happy enough if you help me to solve this. do I need to use delay()?

Thanks in advance for your kind help.

sakilimtiaz:
Hi ieee488,
At First I want to thank you for your help. Every statements work fine except only forward and forward2 does not work. I mean left+forward, left+forward2, right+forward, right+forward2, left, right commands work. I would be happy enough if you help me to solve this. do I need to use delay()?

Thanks in advance for your kind help.

I have no idea what your program is suppose to do.
All I am trying to do is have you understand the logic of your own program.
You need to understand what you want it to do.

if yPosition is greater than 71, irsend.sendNEC(0x3967FD0D, 32); // forward2 is never executed
if yPosition greater than 20 and yPosition is less than 70, irsend.sendNEC(0xC9DC4F09, 32); // forward is never executed

Allow me to apologize. I want to make a 2ch IR transmitter . In arduino UNO it works. But not in attiny85. I found SYMA helicopter remote code for arduino in a blog. I want to make a transmitter using attiny. for rc car it needs forward and left/right signal at the same time. Can you give me some idea to complete the project. Thank you.

Hi,

How does the blog you mention show it sending two iR codes at the same time? Does it instead encode the two into one bitstream? My first hit from the google search shows it as a 32 bit encoded value rather than a choice of multiple iR codes

Geoff

No, this is not the blog but the codes are almost same. When I found, the code is for arduino(not for attiny85). I want to make mine. Thats why I am trying to send 2 analog pin value at a time. Thank you.

I get that you want to make it your own, but you can only send one code at a time and by having one fixed code for turn left, and one for go forward you'll have the ability to go at one speed forward with one turning radius to the left with no ability to change from left to right (say) smoothly. The syma method of encoding it as one string of bits means they can have variable speed and shades of turning - hope that makes sense.

Within the limitations of this design then, it appears you've already seen from post #3 above there are values of xPosition and yPosition where no code is sent.

To debug this you already have debugging serial prints in there commented. Suggest you uncomment those and add a println with the comment content (left+forward etc) in each logic block, run your code and you'll be able to see in the serial monitor what actions the code is taking based on which inputs.

If you're still stuck, paste the results here in CODE tags so we can see what you're receiving and we'll have a better chance of assisting you.

Cheers ! Geoff

Just a little addenda.

Well, I figure that if you are a Web designer, you should be able to follow how to post stuff neatly, so go read the instructions, then go back and mark up the code in your first post so it appears as ieee488 showed it and can be worked with properly.

While I am not following your specific code, one or two points. You have

//activate pull-up resistor on the push-button pin
  pinMode(ledPin, OUTPUT);

but you do not in fact enable the pull-up; you have actually commented out the code to do this.

Also you have defined ledPin as pin one, but pin one is part of the serial interface used for communication including programming. Pin 13 is the default LED pin.

Paul__B:
Just a little addenda.

Well, I figure that if you are a Web designer, you should be able to follow how to post stuff neatly, so go read the instructions, then go back and mark up the code in your first post so it appears as ieee488 showed it and can be worked with properly.

While I am not following your specific code, one or two points. You have

//activate pull-up resistor on the push-button pin

pinMode(ledPin, OUTPUT);



but you do not in fact enable the pull-up; you have actually commented out the code to do this.

Also you have defined ledPin as pin one, but pin one is part of the serial interface used for communication including programming. Pin 13 is the default LED pin.

Allow me to apologize for the delay for my geological position. After follow strykeroz's suggestion I will reply back. If I stuck I will paste the code here.
Thank you very much.

strykeroz:
I get that you want to make it your own, but you can only send one code at a time and by having one fixed code for turn left, and one for go forward you'll have the ability to go at one speed forward with one turning radius to the left with no ability to change from left to right (say) smoothly. The syma method of encoding it as one string of bits means they can have variable speed and shades of turning - hope that makes sense.

Within the limitations of this design then, it appears you've already seen from post #3 above there are values of xPosition and yPosition where no code is sent.

To debug this you already have debugging serial prints in there commented. Suggest you uncomment those and add a println with the comment content (left+forward etc) in each logic block, run your code and you'll be able to see in the serial monitor what actions the code is taking based on which inputs.

If you're still stuck, paste the results here in CODE tags so we can see what you're receiving and we'll have a better chance of assisting you.

Cheers ! Geoff

Allow me to apologize for the delay for my geological position. After follow your suggestion I will reply back. If I stuck I will paste the code here as you mentioned.
Thank you very much.

strykeroz As per your suggestion I uploaded the code into arduino it works perfectly. But it is not working smoothly in attiny85. I think there is some problem in configuration of time.
here is the out put of serial monitor:

X: 140 | Y: 60forward
X: 141 | Y: 72forward2
X: 140 | Y: 86forward2
X: 141 | Y: 91forward2
X: 140 | Y: 96forward2
X: 140 | Y: 104forward2
X: 141 | Y: 109forward2
X: 140 | Y: 104forward2
X: 141 | Y: 94forward2
X: 141 | Y: 84forward2
X: 141 | Y: 73forward2
X: 141 | Y: 89forward2
X: 140 | Y: 83forward2
X: 140 | Y: 71X: 140 | Y: 60forward
X: 139 | Y: 51forward
X: 140 | Y: 52forward
X: 140 | Y: 59forward
X: 141 | Y: 72forward2
X: 139 | Y: 83forward2
X: 141 | Y: 90forward2
X: 140 | Y: 92forward2
X: 141 | Y: 98forward2
X: 141 | Y: 106forward2
X: 141 | Y: 100forward2
X: 140 | Y: 92forward2
X: 140 | Y: 84forward2
X: 138 | Y: 80forward2
X: 141 | Y: 67forward
X: 140 | Y: 50forward
X: 141 | Y: 0X: 141 | Y: 132forward2
X: 149 | Y: 87forward2
X: 148 | Y: 87forward2
X: 123 | Y: 255forward2
X: 107 | Y: 255forward2
X: 97 | Y: 255right +forward2
X: 95 | Y: 255right +forward2
X: 95 | Y: 255right +forward2
X: 113 | Y: 255forward2
X: 125 | Y: 250forward2
X: 136 | Y: 255forward2
X: 144 | Y: 255forward2
X: 151 | Y: 255left + forward2
X: 156 | Y: 255left + forward2
X: 157 | Y: 255left + forward2
X: 145 | Y: 255forward2
X: 135 | Y: 255forward2
X: 123 | Y: 255forward2
X: 111 | Y: 255forward2
X: 102 | Y: 255forward2
X: 99 | Y: 255right +forward2
X: 97 | Y: 255right +forward2
X: 95 | Y: 255right +forward2
X: 103 | Y: 255forward2
X: 110 | Y: 255forward2
X: 119 | Y: 255forward2
X: 130 | Y: 255forward2
X: 140 | Y: 255forward2
X: 150 | Y: 255forward2
X: 156 | Y: 255left + forward2
X: 163 | Y: 255left + forward2
X: 149 | Y: 255forward2
X: 141 | Y: 255forward2
X: 112 | Y: 250forward2
X: 100 | Y: 255forward2
X: 96 | Y: 255right +forward2
X: 96 | Y: 255right +forward2
X: 96 | Y: 255right +forward2
X: 95 | Y: 255right +forward2
X: 100 | Y: 255forward2
X: 104 | Y: 255forward2
X: 116 | Y: 255forward2
X: 132 | Y: 250forward2
X: 145 | Y: 255forward2
X: 154 | Y: 255left + forward2
X: 161 | Y: 255left + forward2
X: 142 | Y: 255forward2
X: 139 | Y: 255forward2
X: 139 | Y: 106forward2
X: 139 | Y: 42forward
X: 148 | Y: 1X: 149 | Y: 3X: 149 | Y: 0X: 148 | Y: 0X: 148 | Y: 0X: 148 | Y: 0X: 149 | Y: 0X: 149 | Y: 0X: 148 | Y: 0X: 148 | Y: 0X: 149 | Y: 3X: 148 | Y: 0X: 147 | Y: 0X: 148 | Y: 0X: 148 | Y: 0X: 148 | Y: 0X: 148 | Y: 0X: 148 | Y: 0X: 148 | Y: 16X: 148 | Y: 58forward

I made the arduino as transmitter. It works perfectly with NEC(code) as I want to do. I stuck when I upload the code into attiny85. It is not working smothly.
One more thing, Can I send the x and y position integer value directly instead of assign them to NEC code ?
I am waiting for your kind advice..

Hi,

That's excellent news. So from here you know your logic is sound so you can eliminate that as a cause.

Are you sure your ATtiny85 is running at full speed? iR is all about timing so that will also be a factor. There's also a tuning sketch for making sure the chip is running as accurately as possible - this page explains how to do that for a similar project.

Geoff

strykeroz:
Hi,

That's excellent news. So from here you know your logic is sound so you can eliminate that as a cause.

Are you sure your ATtiny85 is running at full speed? iR is all about timing so that will also be a factor. There's also a tuning sketch for making sure the chip is running as accurately as possible - this page explains how to do that for a similar project.

Geoff

I burn bootloader as "ATtiny85 @ 16MHz (internal PLL;4.3V BOD)”. But the same problem exist. I check through TinyPcRemote reader using arduino, if I press and hold a TV remote key it print codes continuously. But my attiny85 remote stuck after sending 5-6 codes continuously then IR LED blink but no code received. I already created a remote(attiny85) with push button. if I press and hold push button the same problem happens there also.After sending 5-6 codes continuously it also stuck. I am totally out of idea. Normal tv remote even send code continuously.

sakilimtiaz:
But my attiny85 remote stuck after sending 5-6 codes continuously then IR LED blink but no code received.

So you're seeing the iR LED is still lit (and therefore the ATtiny is still running ok) but the receiver isn't able to decode the messages being sent?

I'd certainly be looking to timing. Does the library you're using allow tuning to calibrate for the oscillator in your particular ATtiny like the one in the link above?

strykeroz:
So you're seeing the iR LED is still lit (and therefore the ATtiny is still running ok) but the receiver isn't able to decode the messages being sent?

I'd certainly be looking to timing. Does the library you're using allow tuning to calibrate for the oscillator in your particular ATtiny like the one in the link above?

actually the library only works with 8MHz (declared on the lybrary) . If i burn bootloader as 16 MHZ PL 4.3v BOD disable, Then I have to use 5v to work. If I use 3.7 v attiny does not run. In 5v it works but same problem occurs. I think the library have some bugs. Because If I send buttonstate through digitalWrite it only send 5-6 codes continuously then LED blinks but no signal to decode. Can I send directly xposition and yposition value by assigning them to a variable and convert them as integer. I mean like this...

irsend.sendRaw(xPosition, yPosition, 32);

I can use a fixed separator to identify both value. Actually I am new to Arduino thats why I could be sound like fool. Please overlook my foolishness as novice. I am looking for your feedback. Thank you very much.

sakilimtiaz:
actually the library only works with 8MHz (declared on the lybrary)

That certainly points to keeping it at that speed then

sakilimtiaz:
If i burn bootloader as 16 MHZ PL 4.3v BOD disable, Then I have to use 5v to work. If I use 3.7 v attiny does not run.

That's unsurprising. On page 163 of the datasheet figure 21-2 shows the ATtiny85 could be out of spec at 16MHz and 3.7V.

strykeroz:
That certainly points to keeping it at that speed thenThat's unsurprising. On page 163 of the datasheet figure 21-2 shows the ATtiny85 could be out of spec at 16MHz and 3.7V.

Can I send raw code using 8MHz BOD disable bootloader?