0

I'm trying to port some Arduino code that I wrote for the Arduino Mega to an ATtiny and I'm having trouble figuring out how to do output. Here is what I have:

char foo;
#include <SoftwareSerial.h>
const int rx=3;
const int tx=4;

SoftwareSerial mySerial(rx,tx);

void setup() 
{ 
mySerial.begin(9600);
} 

void loop() {
 if (mySerial.available()) {
   char data = mySerial.read();
   mySerial.write(data);
 }

 mySerial.println("hello");
}

To my understanding this should print "hello" to the console over and over again but for some reason it uploads successfully but then it doesn't do anything.

Here is the programmer that I am using to connect my ATtiny to my computer: https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide/programming-in-arduino

migrated from electronics.stackexchange.com Jun 6 '16 at 15:59

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 1
    One of the available tags for this forum is Arduino and the other it ATtiny. I don't see how it's not, but I'll copy it to the Arduino exchange if no one here knows the answer. – Fortuna Iwasaki Jun 6 '16 at 14:36
  • You need to open the serial monitor, the Arduino IDE's console only display message concerning the build and the upload status – MathieuL Jun 6 '16 at 14:36
  • @FortunaIwasaki check my other comment. – MathieuL Jun 6 '16 at 14:37
  • @MathieuL I won't be able to post another question for at least 40 minutes. Also I know about the little magnifying glass at the top right. I opened it and there was nothing there. – Fortuna Iwasaki Jun 6 '16 at 14:38
  • Which pins are you connecting the serial adapter to? – Ignacio Vazquez-Abrams Jun 6 '16 at 14:49
3

You don't have any output because you don't have a serial adapter connected to the device. The programmer you have is only for programming and does not support a UART serial connection.

  • Right on point, that programmer don't have the usual ucontroller which manage the Virtual UART connection. – MathieuL Jun 6 '16 at 14:54
  • So in other words there is no way to deliver the output to my computer. Do you by any chance know what kind of serial adapter I can get to connect the ATtiny to my computer? – Fortuna Iwasaki Jun 6 '16 at 14:55
  • Any FTDI/PL2303/CH340G-based serial adapter should work. You should consider disconnecting the chip from the programmer before connecting it though. – Ignacio Vazquez-Abrams Jun 6 '16 at 14:56
  • @FortunaIwasaki You can transfer information to your PC with a UART to USB adapter. – MathieuL Jun 6 '16 at 14:59
  • Most ATtiny's do not have UART at all. So, probably, even with UART to USB adapter you would need to use some software UART. – Darko Jun 6 '16 at 19:30
0

This is writing serial data to digital pin 4. If you have a serial to USB converter attached to pins 3,4 and you have a terminal attached to said serial to USB converter, it will print to that terminal.

Also, on an ATtiny, you have to check which pins are pins 3,4. They are probably not the physical pins 3,4, and it is dependent on which pin mappings you are using (dependent on ATtiny libraries).

  • I'm using the ATtiny Programmer to connect my ATtiny to my computer and according to the diagram pins 3 & 4 are both analog input pins. However, I'm confused as to why the pins matter at all when all I want is for the word "hello" to be displayed in the console. – Fortuna Iwasaki Jun 6 '16 at 14:43
  • Please add a link to the ATtiny Programmer, and I will add to my answer. – uint128_t Jun 6 '16 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.