Audrino NANO -> Digispark Attiny85, Trouble with PIN communication

Hi!

I have trouble with my Audrino NANO which is set to send HIGH or LOW on two PINs D2/D3 to my Digispark Attiny85 PINs P2/P3.

The 2 bit signal to the Digisparkshould should start one of three LED sequences to play until the
bit is shifted to another sequence.

I have tried the sequence on the Digisparks alone which works fine, but when hooked up to the NANO the LEDs just gives constant on, which is not even one of my sequences.

Anyone care to check my code if I missed something?

Audrino Nano code

#include "EEPROM.h"
// ---------------------------------- Pin definitions -----
#define com_pin1 2
#define com_pin2 3

// --------------------------------------------------------------------------------------------------------------------

void setup() {

pinMode(com_pin1, OUTPUT); // Bit1 I/O outout to Sparky Pin2
pinMode(com_pin2, OUTPUT); // Bit2 I/O outout to Sparky Pin4
}

// --------------------------------------------------------------------------------------------------------------------

void loop(){
// send bits to Digispark Attiny, tre LED sequences

// 00 FIRE
digitalWrite(com_pin2, LOW);
digitalWrite(com_pin1, LOW);
delay(2000);

// 01 IDLE
digitalWrite(com_pin2, LOW);
digitalWrite(com_pin1, HIGH);
delay(2000);

// 11 SELECT
digitalWrite(com_pin2, HIGH);
digitalWrite(com_pin1, HIGH);
delay(2000);
}

Digispark Attiny85 code

// ---------------------------------- Pin definitions -----
#define led_low 0 // the PWM pin the leds is attached to
#define led_middle 1 // the PWM pin the leds is attached to
#define led_up 4 // the PWM pin the leds is attached to
#define com_pin1 2
#define com_pin2 3

// the setup routine runs once when you press reset:
void setup() {
// declare pins to be an output:
pinMode(led_low, OUTPUT); // Ledgroups LOW/MIDDLE/HIGH
pinMode(led_middle, OUTPUT);
pinMode(led_up, OUTPUT);
pinMode(com_pin1, INPUT_PULLUP); // Bit1 I/O inout from Nano Pin1
pinMode(com_pin2, INPUT_PULLUP); // Bit2 I/O inout from Nano Pin2
}

// ------------------------------------------------------------------------------------------------
// the loop routine runs over and over again forever:

void loop() {

if (digitalRead(com_pin2) == LOW){
if (digitalRead(com_pin1) == LOW){ // mode 1 = (00) fire
led_fire (0, 0, 255, 55, 10); // ledbrigthness (0-255), min, max, minwait, maxwait
}
}
if (digitalRead(com_pin1) == HIGH){ // mode 2 = (01) idle
led_idle (0, 2, 0, 255, 0, 300); // ledbrigthness (0-255), fadestep, min, max, minwait, maxwait
}
if (digitalRead(com_pin2) == HIGH){ // mode 3 = (11) select
led_select (0, 3, 0, 255, 1000, 130); // ledbrigthness (0-255), fadestep, min, max, minwait, maxwait
}
}

// --------------------------------------------------------------------------------------------

void led_fire (int ledbrightness, int min,int max, int minwait, int maxwait) {
int blink = max;
//while (digitalRead(com_pin2) == LOW){
// set the brightness of pins:
analogWrite(led_low, blink);
analogWrite(led_middle, blink);
analogWrite(led_up, blink);
blink = -blink; // leds alters max/min
// wait for x milliseconds upon min, max
if (ledbrightness <= min) {
delay(minwait);
}
if (ledbrightness >= max) {
delay(maxwait);
}
//}
}

// --------------------------------------------------------------------------------------------

void led_idle (int ledbrightness,int fadestep, int min,int max, int minwait, int maxwait) {
//while (digitalRead(com_pin1) == HIGH){
//set the brightness of pins:
analogWrite(led_low, ledbrightness);
analogWrite(led_middle, ledbrightness);
analogWrite(led_up, ledbrightness);

// change the brightness for next time through the loop:
ledbrightness = ledbrightness + fadestep;

// wait for x milliseconds upon min, max
if (ledbrightness <= min) {
delay(minwait);
}
if (ledbrightness >= max) {
delay(maxwait);
}

// reverse the direction of the fading at the ends of the fade:
if (ledbrightness <= min || ledbrightness >= max) {
fadestep = -fadestep;
}
// wait for x milliseconds to see the dimming effect
delay(8);
//}
}

// --------------------------------------------------------------------------------------------

void led_select (int ledbrightness,int fadestep, int min,int max, int minwait, int maxwait) {
int blink = max;
//while (digitalRead(com_pin2) == HIGH){
// set the brightness of pins:
analogWrite(led_low, ledbrightness);
analogWrite(led_middle, ledbrightness);
analogWrite(led_up, ledbrightness);

// change the brightness for next time through the loop:
ledbrightness = ledbrightness + fadestep;

// wait for x milliseconds upon min, max
if (ledbrightness <= min) {
delay(minwait);
}
if (ledbrightness >= max) {
for (int count = 1; count <= 16; count++) {
analogWrite(led_low, blink);
analogWrite(led_middle, blink);
analogWrite(led_up, blink);
blink = -blink; // leds alters max/min
delay(maxwait);
}
int blink = max; // Resets blink
}

// reverse the direction of the fading at the ends of the fade:
if (ledbrightness <= min || ledbrightness >= max) {
fadestep = -fadestep;
}
// wait for x milliseconds to see the dimming effect
delay(8);
//}
}

How is the wiring? Do they share a common ground? Have you tried use "INPUT" instead of "INPUT_PULLUP" on the tiny?

Hi! Yes, they both share the same GND and 5V source, also tried with and without PULLUP, but same results. Have also tried with a 1k ohm resistor between each of the pins previously wihout any change.

I have measured the pins with a voltmeter and it is clearly giving good values.
like 4.8v on HIGH and under 1v on LOW.

I don't have any other output than the P5 on the digispark to alternate with either as P0/P1/P4 is for the LEDs PWM so I'm pretty much stuck on the P2 and P3.

I would suggest you to make a minimal test setup with one LED on the tiny and one pin for communication. If HIGH is received on the data pin, turn the LED on and otherwise off. If this works you can expand your code from there. When all is working, I would also encourage you to get rid of all calls to "delay()" and use "millis()" for timing instead.

Thanks for the reply Danois90.
I changed the code to just blinking LEDs and I can now see (for what I can tell) that P3 and P5 is no good to send bit states on.

That leaves it to one PIN - P2, which works just fine.
Will be okay with just two animations! :smiley:

Must be a digispark thing I guess!