Hi fellas;
I'm trying to read a .txt file on my server with python and send the message via serial to the Thermal Printer connected to Arduino Mega.
I've found some snippets for arduino, php and python. Mainly from:
http://clete2.com/2009/11/control-lcd-text-over-web-interface-arduino/Clete did exactly what i wanna do but with a LCD display as output device instead of a printer.
So, heres my problem:
When i deploy my arduino code, open the serial monitor and type something, the printer prints out without any problems.
But when i close the monitor and run my python script it won't do anything. Only when i stop running the script the printer prints out "Hello Printer!" which is in the setup() of my arduino code.
Here are the python and arduino codes:
Pythonimport serial
import time
import urllib
ser = serial.Serial('COM3', 19200, timeout=0)
url = "http://www.aerovisual.net/experiments/remoteprint/remote.txt"
previousMessage= ";"
while(True):
message = urllib.urlopen(url).read()
if(previousMessage != message):
ser.write(message)
previousMessage = message
print message
time.sleep(100)
Arduino#include "SoftwareSerial.h"
const int buttonPin = 22;
int buttonState = 0;
int printer_RX_Pin = 6; // this is the green wire
int printer_TX_Pin = 5; // this is the yellow wire
SoftwareSerial Thermal(6, 5);
void setup(){
Serial.begin(19200);
Thermal.begin(19200);
//printer.begin();
pinMode(buttonPin, INPUT);
Thermal.write("Hello Printer!");
Serial.println();
Serial.println("Parameters set");
}
void loop() {
char option;
while(Serial.available() > 0) {
option = Serial.read(); //Take a character from serial port and check what it is
Thermal.write(option); //Push this character to printer
Serial.write(option);
delay(50);
}
delay(500);
}
Thanks for the help.