I would ask a question.
I'm having a strange behaviour using a Tiny84. I've built a circuit prototype on a breadboard using 2 gas sensors, an MQ-4 and an MQ-7.
Using those sensors with an Arduino UNO I get correct readings from them (checked on the serial monitor).
So I decided to build a circuit around a Tiny84. To check if the readings are correct I use NewSoftSerial to send the values to Arduino UNO and then I read them from the serial monitor.
I've noticed that only the first analog read is correct, the second one seems to be influenced by the previous one.
I mean that if I read the first sensor I get, i.e., 274. On the 2nd I get 188. If I connect the 1st sensor to 5V, I get 1023 but on the 2nd one I get ~850. If I connect the 1st to GND I read 0, on the 2nd one I read around 188. Using an Arduino everything is correct and the analog pins connected to the sensors work indipendently.
It seems that I cannot do 2 readings in sequence. Is this normal for the Tinys or is there something in the Core libs?
It is entirely possible that you have encountered a bug in the Tiny Core. While I tried very hard to thoroughly test it, I have been known to occasionally make a mistake.
I can say that the 0.1 uF capacitor across VCC and GND is critical. In my testing, without the capacitor, analog read values on ATtiny processors are erratic.
Only One doesn't make errors, and He does not reside on this planet XD
I can say that the 0.1 uF capacitor across VCC and GND is critical. In my testing, without the capacitor, analog read values on ATtiny processors are erratic.
I always use a 0.1 uF cap between Vcc and Gnd of every micro I use for decoupling.
Have you tried performing three reads from the same input to see if the read value approaches the expected value?
I use to read the same analog bin about 10-20 times, with a 1 ms delay from each other, and then return the last reading, to let the S&H charge correctly. After I read the first pin my sketch waits for about 50 ms then it starts reading the second one using the same routine.
But I've also tried to read the pin only 1 or 2 times but nothing have changed.
An update.
I've tried a different Tiny and a different couple of pins and it worked.
So I mounted back the first Tiny84 and used a different couple of pins and it worked.
I discovered that I used A0/A1 pins and then A1/A2 pins.
But looking at the datasheet I've found that A0 is also the AREF pin... so it seems that you cannot use the AREF pin as a normal analog input, am I right?
so it seems that you cannot use the AREF pin as a normal analog input, am I right?
It should work. The datasheet indicates that, when REFS1 REFS0 = 0 0, the AREF pin is free to use as we please. I believe I tested it but it's been many months so I could easily be wrong.
You are not calling analogReference, correct?
Please print the value of ADMUX right after calling analogRead(0) (e.g. Serial.println(ADMUX,HEX);). You do not need to have anything connected to A0.
After calling analogRead(0), is there a stable voltage on the AREF pin?
Thanks again for taking the time to run these tests.
Are you calling pinMode or digitalWrite? Maybe there is a pin-mapping bug and A0 is getting turned into an output. Or the internal pull-up is being enabled.
After calling analogRead(0), is there a stable voltage on the AREF pin? 4V64
Does connecting a pull-down resistor to A0 change the voltage?
I'm running out of ideas. Will using A1 and A2 cause any problems?
I'M SO SORRY.... =(
I wasted your time searching non-existing bugs...
I didn't notice that I was using A0/D10 as the RX pin for NewSoftSerial..... SORRY.
Deleting it, everything has started to work perfectly!
I was using the serial to debug my sketch and my circuit... Me stupid...
Atmel has released new versions of ATtinyx4 marked "A" (ATtiny24A/44A/84A) that, it seems, should differ from the previous ones for the adoption of the PicoPower core.
Does the Tiny core support them? Or do you have in mind to add the support for them shortly?
A question about PWM.
Is it me or it isn't possible to use more that 1 PWM signal?
I would like to fade an RGB LED using PWM signals on digital pins 2-3-4 using analogWrite but I'm having strange results. It seems that 3 PWM signals cannot be used together: only the last one appears to work.
Is it a limit of the Tiny core or a limit of the micro itself?
leo72:
Atmel has released new versions of ATtinyx4 marked "A" (ATtiny24A/44A/84A) that, it seems, should differ from the previous ones for the adoption of the PicoPower core.
Does the Tiny core support them? Or do you have in mind to add the support for them shortly?