basically I want to take pictures with my webcam and print them from a thermal printer connected to arduino.
I'm using this function to store values directly into my arduino sketchfolder
void processImage() {
println("Loading image...");
filename = "adalogo";
img = loadImage((pic-1)+"video.jpg");
// Morph filename into output filename and base name for data
x = filename.lastIndexOf('.');
if (x > 0) filename = filename.substring(0, x); // Strip current extension
x = filename.lastIndexOf('/');
if (x > 0) basename = filename.substring(x + 1); // Strip path
else basename = filename;
filename += ".h"; // Append '.h' to output filename
println("Writing output to " + filename);
// Calculate output size
rowBytes = (img.width + 7) / 8;
totalBytes = rowBytes * img.height;
// Convert image to B&W, make pixels readable
img.filter(THRESHOLD);
img.loadPixels();
// Open header file for output (NOTE: WILL CLOBBER EXISTING .H FILE, if any)
//String adalogo = "adalogo";
String path = "/Users/ricks/Documents/Arduino/myprint/adalogo.h";
output = createWriter(path);
// Write image dimensions and beginning of array
output.println("#ifndef _" + "adalogo" + "_h_");
output.println("#define _" + "adalogo" + "_h_");
output.println();
output.println("#define " + "adalogo" + "_width " + img.width);
output.println("#define " + "adalogo" + "_height " + img.height);
output.println();
output.print("static const uint8_t PROGMEM " + "adalogo" + "_data[] = {");
// Generate body of array
for (pixelNum=byteNum=y=0; y<img.height; y++) { // Each row...
for (x=0; x<rowBytes; x++) { // Each 8-pixel block within row...
lastBit = (x < rowBytes - 1) ? 1 : (1 << (rowBytes * 8 - img.width));
sum = 0; // Clear accumulated 8 bits
for (p=128; p>=lastBit; p >>= 1) { // Each pixel within block...
if ((img.pixels[pixelNum++] & 1) == 0) sum |= p; // If black pixel, set bit
}
if (++bytesOnLine >= 10) { // Wrap nicely
output.print("\n ");
bytesOnLine = 0;
}
output.format(" 0x%02X", sum); // Write accumulated bits
if (++byteNum < totalBytes) output.print(',');
}
}
// End array, close file, exit program
output.println();
output.println("};");
output.println();
output.println("#endif // _" + "adalogo" + "_h_");
output.flush();
output.close();
println("Done!");
myPort.write('H'); //starts the printing in arduino
}
Then my arduino reads:
char val;
int ledPin = 13;
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#define TX_PIN 2 // Arduino transmit YELLOW WIRE labeled RX on printer
#define RX_PIN 3 // Arduino receive GREEN WIRE labeled TX on printer
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
void setup() {
:
pinMode(7, OUTPUT); digitalWrite(7, LOW);
pinMode(ledPin, OUTPUT);
// NOTE: SOME PRINTERS NEED 9600 BAUD instead of 19200, check test page.
Serial.begin(9600); // Initialize SoftwareSerial
printer.begin(); // Init printer (same regardless of serial type)
// Print the 75x75 pixel logo in adalogo.h:
/*printer.sleep(); // Tell printer to sleep
delay(3000L); // Sleep for 3 seconds
printer.wake(); // MUST wake() before printing again, even if reset
printer.setDefault(); // Restore printer to defaults*/
}
void loop() {
while (Serial.available()) { // If data is available to read,
val = Serial.read(); // read it and store it in val
}
if (val == 'H') { // If H was received
#include "adalogo.h"
//#include "adaqrcode.h"
digitalWrite(ledPin, HIGH); // turn the LED on
Serial.println("H");
mySerial.begin(19200); // Initialize SoftwareSerial
//Serial1.begin(19200); // Use this instead if using hardware serial
printer.begin(); // Init printer (same regardless of serial type)
printer.printBitmap(adalogo_width, adalogo_height, adalogo_data);
printer.sleep(); // Tell printer to sleep
delay(1); // Sleep for 3 seconds
printer.wake(); // MUST wake() before printing again, even if reset
printer.setDefault(); // Restore printer to defaults
if (val == 'J'){
printer.sleep();
}
} else {
digitalWrite(ledPin, LOW); // Otherwise turn it OFF
}
delay(1); // Wait 100 milliseconds for next reading
}
The Problem is that the arduino always prints the picture that was stored at the time I start the sketch. Is there any way to update the file and resend it to the arduino?