About a year ago I wrote a code for an adafruit thermal printer. As the wiring was really bad back then, I'm fixing it now. But my wiring doesn't work anymore...
The printers RX and TX are connected to my micro pro as shown in the code below. For debugging, I'm ignoring all voids, except for "void printing". (The rest of the code is for accessing a SD-card, and this works)
The printer is connected to 9V and gets his 9V. The ground of the printer is connected to a ground on the arduino, so they share a common ground. Furthermore, the connections for RX and TX are good, I checked them with a multimeter.
The printer itself works. I jumped the J1 contacts and the test-page is printed. There i also see that baudrate of 9600 is correct.
But when starting my code, it says that void printing is entered, but is doesn't print. The example code isn't printed as well. I just can't find why...
I just assume the error lies somewhere with my RX/TX connections, but otherwise I'm clueless...
They are not "voids". They are functions. The keyword void in the declaration of a function simply means that the function does not return a value.
But functions can return a value, where that is useful or makes your code more readable. For example, your function countlines() could be improved by returning a value:
int countlines(){
myFile=SD.open(fileName);
if(myFile){
int zaehlerzeile=0;
while(myFile.available()){
cha=myFile.read();
if(cha=='\n'){
zaehlerzeile++;
}
}
zaehlerzeile++;
}
myFile.close();
//Serial.println(maxzeile);
return zaehlerzeile;
}
You should not be using software serial on Pro Micro because it has a hardware serial port available. We should never use software serial where there is a hardware serial port available to use.
@halbflauschmammut sorry if my comments are not solving your immediate problem. I am reviewing what you put in your post and these are things that occur to me.
Do you have a serial-usb adapter that you could use for testing?
Pro Micro are available in 3.3V and 5V versions. If you have the 3.3V and the printer expects 5V signals, this could be the problem. You may need to boost the signal. This is pretty easy to do with just a transistor and a couple of resistors, for example.
This is welcome as I'm a beginner. But since this part of the code isn't my problem at the moment, I'm not worried about this. I might change this when the more urgent problems are solved.
I honestly don't know what a serial-usb adapter you mean... I have the micro connected to my PC and watch via serial monitor what's happening.
I changed the code and rewired the printer, but still no printing...
They are a generally useful thing to have in your arduino toolbox.
You could connect one to the Tx output of the Pro Micro instead of or in parallel with the printer. When you connect it to your PC with a USB cable, a new COM/tty port/device will appear. You can select that, open serial monitor, set 9600 baud, and see exactly what characters (if any) are being sent to the printer by your code.
Alternatively you could use it to connect your PC directly to the printer without using the Arduino. You could send commands to the printer from the serial monitor and see the response the printer sends back.
Can I just check you understand that when using the hardware serial port on Pro Micro, the pins are 0 and 1, you cannot choose other pins like you can with software serial.
You could try an led (+ series resistor) in place of the printer. You should see the led flickering as the data is sent. You might need to dim the lights in the room to see it at all. Or you might see the led is lit all the time, but as the data is sent, it flickers dimly
This doesn't prove that the correct data is being sent or received correctly by the printer, but at least it indicates that some data is being sent!