Arduino Forum

Using Arduino => Microcontrollers => Topic started by: hamisu-anguan on Jan 17, 2018, 10:43 am

Title: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 17, 2018, 10:43 am

I has been programming using UNO and my project working well.  Then I try to switch to breadboard ATMega328P in TQFP is also working well. 


But I cant get my program to work on ATTiny85. The same program can run perfectly when I use ATMega328P-CU in TQFP. (Of course when i change to ATTiny, I have change the data, clock, latch pins according to ATTiny85 pin configuration).   

My program is just reading the variable resistors and shift out the output into two shift registers of 74HC595. Because i think the number of pins in ATTiny85 is sufficient to run this project, so I do not want to use excess pins in ATMega328P. 

The only different i thought is in ATTiny85, I cant have external crystal and I thought is the speed to slow, then I try burn bootloader for the ATTiny to 8MHz, it is still not working even though all upload is perfect.  There is no errors.

Could someone experience this tell me what is the different and how to get this work ?





Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: Smajdalf on Jan 17, 2018, 04:18 pm
The error on line 131 of your sketch explains the behavior you described.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: DrAzzy on Jan 17, 2018, 04:42 pm
Probably a bug in the code that compromises compatibility. Post the entire sketch (no snippets - it's never in the snippet you think it is).

Also, what board package are you using to add support for the ATTiny85? Mine, or some other one?
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 18, 2018, 03:09 am

I attached the entire code.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: DrAzzy on Jan 18, 2018, 04:39 am
Which board package are you using to add support for ATTiny85?

There are two currently maintained attiny board packages, plus dozens of abandoned versions around the internet, and they are NOT all the same.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: Smajdalf on Jan 18, 2018, 06:50 am
This is likely wrong:
int probe = PB2;
I guess you are reading wrong pin because naming of digital pins is different from naming of analog pins. Try probe = 1;
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 18, 2018, 03:02 pm
I have try naming with numerical number is still not working.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: DrAzzy on Jan 18, 2018, 03:38 pm
Which attiny board package are you using???
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: Smajdalf on Jan 18, 2018, 03:44 pm
You should
1) answer DrAzzy's question
2) try to describe "not working"
3) try to isolate the problem: are you able to turn on/off simple LED? Are you able to shift (constant) data to the shift register? Are you able to read the ADC value properly?
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 19, 2018, 09:28 am

I am using ATTiny/UNO on board shield for ATTiny connected UNO. I can upload program and turn on LED with a simple blink program without issue. May be I shall breakdown the code to check the ADC value using serial monitor. I have not done that.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: wilykat on Jan 19, 2018, 10:17 am
You still haven't answered one question: there are a few different ATTiny cores for Arduino IDE and not all have the same pin naming or coding.  Which one are you using?  Those are listed in Board section of Arduino IDE.  On my IDE I have attiny by David A Mellis v1.0.2
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 19, 2018, 02:07 pm

Yes. I am using David Mellis core, but I dont know what version. I follow the instruction here.

https://www.hackster.io/arjun/programming-attiny85-with-arduino-uno-afb829 (http://Yes. I am using David Mellis,I dont know what version. I follow the instruction here.  https://www.hackster.io/arjun/programming-attiny85-with-arduino-uno-afb829)

Now, I try to install the SpenceKonde core. But I during installation, I have error as below.

I am not sure due to server issue or network issue.





Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 19, 2018, 02:25 pm

after downloaded, CRC mismatch error. Pls help.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: DrAzzy on Jan 19, 2018, 03:40 pm
Can anyone else confirm whether this problem is happening for them? I can't test it until I get home late tonight.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: kprims on Jan 19, 2018, 04:04 pm
I went from version 1.1.4 to 1.1.3 and back to version 1.1.4 without a problem.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: DrAzzy on Jan 19, 2018, 05:24 pm
Hm - sounds like an issue specific to hamisu-anguan's network (or a transient issue that has passed now).

The manual install described here https://github.com/SpenceKonde/ATTinyCore/blob/master/Installation.md will work regardless.

Looking at your code, I think I see the problem (this analysis ONLY applies to my core, I don't know how David handles this; handling the analog vs digital pin numbers has been an incredible headache for me). Pxn type notation (like PB2) will never work with arduino pin manipulation functions. Not on my core or any other core; these are already defined by the compiler, and they are not defined to something that can be used to do what you want. You must use the Arduino Digital Pin Numbers, the A# defines for the analog pins.

With 1.1.4 and later of my core, you can use A# constants for pinMode()/digitalWrite() and analogRead() - however the inverse is not true - if you pass a digital pin number to analogRead() it will not read the pin you expect it to. There's no way to tell when someone does analogRead(1) that they mean the ADC channel attached to digital pin 1, vs ADC channel number 1. There is no way to resolve this without breaking backwards compatibility in a major way (there is a lot of code in use, some of it in actual business applications, that uses ADC channel numbers
This code:
Code: [Select]
//Pin Analog1 as probe pin, uP (1 input Pin)
int probe = PB2;
//Pin connected to ST_CP of 74HC595, (uP 2nd Output Pin)
int latchPin = PB3;
//Pin connected to SH_CP of 74HC595, (uP 3rd Output Pin)
int clockPin = PB0;
////Pin connected to DS of 74HC595, (uP 4th Output Pin)
int dataPin = PB4;


Change to:
Code: [Select]

//Pin Analog1 as probe pin, uP (1 input Pin)
int probe = A1;
//Pin connected to ST_CP of 74HC595, (uP 2nd Output Pin)
int latchPin = 3;
//Pin connected to SH_CP of 74HC595, (uP 3rd Output Pin)
int clockPin = 0;
////Pin connected to DS of 74HC595, (uP 4th Output Pin)
int dataPin = 4;


Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: Smajdalf on Jan 19, 2018, 08:04 pm
I think PBx is #defined as x so it should no be problem here but you are right it should not be used: it will fail for (most of) other Arduinos.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 20, 2018, 01:44 am
Oh...I manage to installed it.

It doesnt work when VPN is ON.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 20, 2018, 01:54 am

Thank you DRAzzy for the clarification. This pin notation is really headache.

Sowhen I use as Analog pin, I define it as A1.
If I use it as Digital Pin, I will have to use pinMode to define input or output and make it as Pin number 2 ?

Am I right ?
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 20, 2018, 02:36 am

I already install the DrAzzy ATTiny core successfully and the compile do not have error. So I uploaded the following program into my shield.

I try to use the Analog read with a smaller code, the problem is my Serial Monitor doesnt show any things.



*/
//Digital Pin1 is PWM Output to drive the L293 (In ATTiny shall be 1 )
//Pin A1 as Analog probe pin

int probe = A1;
int val;

void setup()
{
pinMode (1, OUTPUT);   
Serial.begin(9600);
}

void loop()
{
    int pulseWidth;
    int val = analogRead(probe);
    Serial.println(val);
    delay(500);

    pulseWidth = map (val, 0, 1023, 0, 255);
    analogWrite(1, pulseWidth);
   
}


Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 20, 2018, 06:14 am

May I know the Timer1 clock in DrAzzy ATTiny core shall be set to CPU ?
At what situation it set to 32 or 64 MHz ?

What about LTO  ? Shall I enable it since i am using IDE version 1.8.2 ?

Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: DrAzzy on Jan 20, 2018, 05:27 pm
Leave timer clock at the default setting (not clocked off pll) unless you are doing high frequency pwm.  Lto can be turned on, yes - it'll make the compiled sketch smaller.
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 21, 2018, 12:35 pm

But my Serial monitor still doesnt show anything. Is that not able to use or I still have something wrong in my setup ?
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: Smajdalf on Jan 21, 2018, 02:12 pm
(Standalone) ATTiny is unlikely to have Serial monitor unless you add it and use USB emulation like Digispark or some USB/TTL interface (i.e. Arduino).
Title: Re: ATTiny85 with 74HC595 not matching ?
Post by: hamisu-anguan on Jan 22, 2018, 03:32 pm

But i am using UNO with a shield to program this ATTiny85. seem like this method does not have the facility to debug with Serial. Any others way we can use to be able to program and debug with serial ?