Serial communication using FTDI <> USB cable and ATtiny85 [SOLVED]

Hello everybody ! :slight_smile:

I want to use serial communication for debugging purposes on a project using an ATtiny85.
I program the ATtiny85 using the Arduino IDE and the Tiny AVR programmer.

I know that the ATtiny85 has no hardware for serial communication. That's why I am using a FTDI <> USB cable and the SoftwareSerial library.

The code below is a test sketch. It basically blinks the LED on the Tiny AVR Programmer when it is running, sending some Serial data at the same time. The problem is that I didn't manage to receive anything on my serial monitor, even though the LED is blinking correctly. It is set at 9600 bauds at both ends.

#include <SoftwareSerial.h> 
#define tx 1
#define rx 2
int blinkPin = 0;

SoftwareSerial mySerial(rx, tx); 
void setup()
{
  CLKPR = 0x80;           // Prescaler changes enabled 
  CLKPR = 0x00;           // Prescaler set to 1 to run at 8 MHz 
  mySerial.begin(9600);   // 9600 bauds
  delay(500);
  pinMode(blinkPin, OUTPUT);
  mySerial.println("Conf OK");
 
}

void loop()
{
  digitalWrite(blinkPin, HIGH);
  mySerial.println("HIGH");
  delay(1000);
  digitalWrite(blinkPin, LOW);
  mySerial.println("LOW");
  delay(1000);
}
  • As I said, everything is set at 9600 bauds;

  • I tried to increase the clock speed to 8 MHz by disabling the prescaler on the ATtiny85 (thought the 1 MHz factory default setting would be too slow). It corresponds to the CLKPR = 0x80; CLKPR = 0x00; in my code.

  • I am using the right wires for the FTDI cable : black as GND, white (RXD) and green (TXD). I opened the cable to access the FTDI chip and those wires are welded correctly.

  • When plugged to an USB port, the FTDI cable seems to be recognized by my computer (/dev/tty.usbserial-1420).

  • I installer the drivers from the FTDI website.

  • I am using a MacBook Air with macOS 10.14.

  • I tried to use both the Terminal from my Mac for the serial communication, as well as the one from the Arduino IDE. When using the Arduino IDE I select the AVRISP mkII as a compiler as advised here: Easy Serial on the ATtiny - Hackster.io

  • I tried to use several USB ports on my computer.

I can't find what's wrong here. Also note that this is the first time I am using that cable, so I cannot be sure the cable itself is working properly / the drivers are working.

Any idea about something I should try ?

Thank you very much !!

Just a small update to let you know that I tried to use a different computer for the serial communication, in case it would be an issue with the driver on my Mac.I used a Windows 10 computer.
It recognized the FTDI cable and installed the drivers automatically. I used PuTTY, set at 9600 bauds, on the appropriate COM port. Unfortunately it didn't work.

I also tried to use a different PIN for the TX on the ATTiny85 in case the one I chose would be incompatible with the Software Serial library. It didn't work either.

Is there a chance it coud be related to a clock frequency issue ? When I select the prescaler to 1, I have a clock frequency of 8 MHz. Would that be compatible with a 9600 bauds communication ? I doubt that would be the issue, but who knows...

If you have any idea ? Thank you very much in advance ! :slight_smile:

Did you try swapping RX and TX again? That's always the first thing I do.

This link shows how to test a FTDI cable for good or bad.

The cable you have may have a FTDI chip but not be manufactured by FTDI, if this is the case the wire color code may be different so take care when testing, shorting the wrong wires will destroy your chip.

https://www.ladyada.net/wiki/ftditest

sumguy:
This link shows how to test a FTDI cable for good or bad.

The cable you have may have a FTDI chip but not be manufactured by FTDI, if this is the case the wire color code may be different so take care when testing, shorting the wrong wires will destroy your chip.

ftditest [AdaWiki]

Thank you for this link. I performed the cable test. Everything worked as it should have.
The only doubt I have is for the test between black and orange wires (black and green for my cable, TXD). Instead of 3.3 V I measured only 3.17 V. I assume this is "within tolerance" ? (All the other tests worked fine.)

Now I think I can assume that my cable is fine, which is good to know. Thanks about that ! :slight_smile:

Still doesn't explain why my sketch isn't functioning though ! That's strange because the LED seems to blink as it should, which would indicate that the ATTiny85 works as expected...

Power_Broker:
Did you try swapping RX and TX again? That's always the first thing I do.

Thank you very much !!

You were right ! I feel stupid, but it worked ! :smiley:

I didn't think about it, I considered the TXD and the RXD lines from the perspective of the ATTiny85, but it should have been from the perspective of the receiving computer apparently.

I will be able to debug my project now, what a relief to have serial communication !

Thank you very much to the both of you for your contributions !

Cheers ! :slight_smile:

For the record I am assuming that Power_Broker provided the solution of the tx and rx being crossed and your last post had the wrong quote pasted in.

Knowing the solution is good for those that follow with the same problem.

sumguy:
For the record I am assuming that Power_Broker provided the solution of the tx and rx being crossed and your last post had the wrong quote pasted in.

Knowing the solution is good for those that follow with the same problem.

Indeed, Power_Broker provided the solution ! That's now corrected, I edited my message !

:wink: