help with project

hi guys,

i got the code below that works fine via the arduino and a breadboard, everything does what its supposed to do, but when i load it up into an attiny45 everything works except the morse code on pin B1

ive checked the chip with another program known to work and thats fine, tried a different one to be sure, checked the led which works and if i program it to read high it turns on by the attiny45.

i also tried the morse on another pin and nothing on that either.

so its literally the morse code aspect that doesnt work on the chip but does on a breadboard.

any ideas? (also the other state was added to see if that made a change and is removable.)

#define PIN_STATUS 1

#include <LedFlasher.h>
#include <morse.h>

LEDMorseSender sender(PIN_STATUS);
const byte WTPin = 2;
const byte CPLPin = 4;
const byte motorPin = 3;

typedef enum
  {
  initialState,
  wantCockpit,
  wantadditional,
    }
    
states;
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 5;

void setup ()
  {
  pinMode (WTPin, OUTPUT);
  pinMode (CPLPin, OUTPUT);
  pinMode (motorPin, OUTPUT);
  sender.setup();
  sender.setMessage(String("h "));
  }
  
void doStateChange ()
  {
  lastStateChange = millis ();
  timeInThisState = 5;
  switch (state)
  
   {
    case initialState:
         state = wantCockpit;
         break;
         
    case wantCockpit:
         sender.startSending();
         digitalWrite (WTPin, HIGH);
         digitalWrite (motorPin, HIGH);
         state = wantadditional;
         timeInThisState = 10000;
         break;

     case wantadditional:
     timeInThisState = 1000;
     state = wantCockpit;
     break;
    }
  }
  
void loop ()
{
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();
   if (!sender.continueSending())
 {
    sender.startSending();
  }
}

I'm not sure what you mean by pin 1. Pin 1 of Arduino is port D1. Pin 1 on ATTiny45 is !Reset, or maybe you mean port B1?

I also don't see any morse code pin in your sketch. Is there another pin used for that?

mityeltu:
I’m not sure what you mean by pin 1. Pin 1 of Arduino is port D1. Pin 1 on ATTiny45 is !Reset, or maybe you mean port B1?

I also don’t see any morse code pin in your sketch. Is there another pin used for that?

Hi there the pins are the actual pin assignments for the attiny45 chip as used in the code, so pin 1 is the second up from bottom on right side of the chip. (Pb1?)

The Morse is defined as pin_status 1

Like I said it all works on the breadboard (for the breadboard I reassign pin 1 to pin 13 cause you know, arduino uno doesn’t like pin 0 or 1 used haha) and the led does work on the circuit it’s just when the sketch is loaded into the chip it doesn’t run the Morse code

I’ve attatched the Morse library files for reference as well

morse.h (3.05 KB)

morse.cpp (4.46 KB)

Here the circuitry, it all works fine, if digitalWrite HIGH style code is used the 2 relevant leds turn on, if using blink sketch they will blink.

ignore the top half of it, its the bottom IC thats important here, the top ones just controlling a fire effect

Honestly don’t know what’s going on with the Morse code part of this

does anyone have anuy ideas on this one?

If it worked on the breadboard with the Arduino and you correctly ported the code for the ATTiny, then the error will be in the wiring.

mityeltu: If it worked on the breadboard with the Arduino and you correctly ported the code for the ATTiny, then the error will be in the wiring.

Except it's not, if I use the blink sketch the circuit works perfectly fine

Well, again, if it been ported correctly, then the problem is in the wiring. Conversely, if it's wired correctly, the problem is in the porting to the ATTiny.

I don't follow all your code, so I can't help you much more than that. Sorry. Good luck.

mityeltu: Well, again, if it been ported correctly, then the problem is in the wiring. Conversely, if it's wired correctly, the problem is in the porting to the ATTiny.

I don't follow all your code, so I can't help you much more than that. Sorry. Good luck.

Tjats why I don't get what's going on, its wired perfectly fine and ported currently, I don't understand what's going on

My last suggestion would be the "rubber duck" method. Sounds stupid, but it works magic sometimes.

Get a rubber duck - or other inanimate object you don't mind talking to, and then, line by line, tell your rubber duck what that line is supposed to make your program do. If you make it through all that, I would go back to the board and recheck all the wiring. Ohm out the points to make sure you're not bridging somewhere.

Best suggestions I have.

mityeltu:
My last suggestion would be the “rubber duck” method. Sounds stupid, but it works magic sometimes.

Get a rubber duck - or other inanimate object you don’t mind talking to, and then, line by line, tell your rubber duck what that line is supposed to make your program do. If you make it through all that, I would go back to the board and recheck all the wiring. Ohm out the points to make sure you’re not bridging somewhere.

Best suggestions I have.

But this wouldn’t help, the code works perfectly fine on the breadboard and the circuit is wired perfectly fine as other sketches work fine in testing it. So the problem is somewhere between them as best I can tell

Look, there are only 3 variables here. The board, the chip and the code. If the chip is not damaged in some way, then the problem is with the code or the board. If you eliminate one of those, then the problem MUST be with the other one. Pick one. You have my suggestions. If you're not willing to even go digging, you won't ever strike gold.

mityeltu: Look, there are only 3 variables here. The board, the chip and the code. If the chip is not damaged in some way, then the problem is with the code or the board. If you eliminate one of those, then the problem MUST be with the other one. Pick one. You have my suggestions. If you're not willing to even go digging, you won't ever strike gold.

Listen mate I've been over everything with a fine tooth comb. Circuit works! Code works! When code added to chip part of the code doesn't run.

I've tried every test I can and everything works individually but not as a whole

Could there be some conflict between the libraries and the chip? Like a compatability issue?

Despite already confirming the Circuit Is good, I put the chip into a breadboard and simplified the rig so it's just the 2 leds, resistors and relevant jumper wires, the Morse code is still not working when loaded to the chip, I've also due ked it on another pin on the chip and nothing.

As best I can see there's a problem with the libraries and the chip. But I don't understand the libraries enough to see where the problem is or how to fix it.

okay so its definately a problem with the libraries, when i use the code below which is the same, but with the morse code library and code removed and replaced with the flash library and a pause using case wants everything works fine,

this is a work around for this particular part but isnt any good for sending more than a single letter or one where there are dashs and dots.

//Messerschmitt_Program_with_Morse_Code
#include <LedFlasher.h>
const byte IdPin = 1;
const byte WTPin = 2;
const byte motorPin = 3;

LedFlasher Id     (IdPin,    300,       300,     false);

typedef enum
  {
  initialState,
  wantCockpit,
  wantIdOn,
  wantIdOff,
  }
    
states;
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 5;

void setup ()
  {
  pinMode (WTPin, OUTPUT);
  pinMode (motorPin, OUTPUT);
  pinMode (IdPin, OUTPUT);
  }
  
void doStateChange ()
  {
  lastStateChange = millis ();
  timeInThisState = 5;
  switch (state)
  
   {
    case initialState:
         state = wantCockpit;
         break;
         
    case wantCockpit:
         digitalWrite (WTPin, HIGH);
         digitalWrite (motorPin, HIGH);
         state = wantIdOn;
         timeInThisState = 10;
         break;

    case wantIdOn:
         Id.on();
         state = wantIdOff;
         timeInThisState = (2500);
         break;

    case wantIdOff:
         Id.off();
         state = wantIdOn;
         timeInThisState = (1000);
         break;
    }
  }
  
void loop ()
{
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();
     Id.update();

}

so the problem definately lies in the libraries and compatibility with the attiny45s

can someone with more knowledge than me look over the libraries and see whats wrong? i dont have a clue what im looking for or where to start.

morse.cpp (4.94 KB)

morse.h (7.15 KB)

Ok, good, you've isolated the problem apparently to the code, this is what I was getting at. There is a problem with then porting of your code from the Arduino to the ATTiny.

From your original post, the code looks to say that PIN_STATUS indicates the pin used to send morse on the led. Is this correct?

For what I say next, I will assume the affirmative.

My first response to your original post asked if PIN 1 on the arduino matches PIN 1 on the ATTiny. Can you verify that when you port code from the Arduino using PIN 1 that the same PIN even exists on the ATTiny. What I mean is, the library you are using (arduino) may be roouting this differently than can be done on the attiny. Do you understand? I amy be wrong. I frankly don't have that much experience with this, but it seems to me that the library is simply using a pin that you have improperly assigned.

I don't know if that helps at all, but maybe ut's a place to start with the library troubleshooting.

I'll expand on this when home as on phone at moment.

Its a compatibility issue, the chip simply doesn't have the ability to run the library, it's not advanced enough it seems. Something relating to hardware multipliers?

You'll want to look closer at ATtiny compatibility. I've never used one but here's a Stack Overflow article that seems helpful. https://electronics.stackexchange.com/questions/80292/what-cant-the-attiny-do-that-the-arduino-can It does mention that ATtiny doesn't have a full hardware-multiply implementation for factors other than 2. I notice in this "morse.cpp" that at least one function calls on floating-point multiply in MorseSender::setWPM(). Might be more spots; that's the first one I noticed. Good luck, Barry

from https://github.com/markfickett/arduinomorse/issues/11