Sorry about delay, I was busy and forgot.
My sketch uses a simple PCD8544.h library by carlosefr (there is information how connect LCD to board) https://github.com/carlosefr/pcd8544 and SoftwareSerial.h to connect directly to RX and TX (D1 and D0) Polargraph's board.
SD connection described in sketch.
Before using this controller You need configure polargraph directly from PC through program Polargraphcontroller. Also I changed this parameters in Polargraph's original sketch:
int rebroadcastReadyInterval = 500;
boolean automaticPowerDown = false;
If your polargraph works fine with PC, you can connect it to second arduino - controller. Controller's D8 to Polargraph's TX(D0) and D9 to RX (D1). And now you must not connect Polargraph via Usb and power it by +5V and GND pins from controller which can power via USB but it not good idea. You can see debug information from controller in Serial terminal but it can reset arduino and drawing is broke.
Now you need run Proccesingcontroller software and make Queue file. After start your queue must contain 3 lines like C02.....C31.....C32
Its ok and contain pensize, speed and acceleration information.
Next step: press SET HOME.
And now you can make rendering commands as usual (load image file, select area, render pixels.... or another steps)
After rendering commands you can press RETURN TO HOME, its adds return home command after drawing.
Finally in QUEUE window press EXPORT QUEUE and save QUEUE.TXT file on your SD card (it must FAT32)
Put SD on controller slot, manually set gondola to home position and turn on power.
If SD and file OK screen show filesize (as you can see on video higher( and now you can press RUN button and it will start draw!!!
#include <SPI.h>
#include <SD.h>
#include <PCD8544.h>
#include <SoftwareSerial.h>
static PCD8544 lcd;
SoftwareSerial mySerial(8, 9); // RX, TX to polargraph
File myFile;
char mode; //mode: 1=reading and send, 2=pause, 0=stop
char next; //flag reading next line in file
unsigned long pos; //position in file
unsigned long fsize; //filesize
unsigned long now; //
unsigned long sec;
char rbf; //Read Byte from file
char rbs; //Read Byte from serial
char buff[10]; //buffer
char i;
boolean cls; //clear screen line;
boolean SDok;
static const byte play[] = {0x7f, 0x7f, 0x3e, 0x1c, 0x08};
static const byte pause[] = {0x7f, 0x7f, 0x00, 0x7f, 0x7f};
static const byte stp[] = {0x7f, 0x7f, 0x7f, 0x7f, 0x7f};
//static const byte wait[] = {0x63, 0x75, 0x69, 0x75, 0x63};
//static const byte hom[] = {0x7c, 0x46, 0x57, 0x46, 0x7c};
//static const byte penup[] = {0x40, 0x47, 0x4e, 0x47, 0x40};
//static const byte pendown[] = {0x40, 0x5f, 0x78, 0x5f, 0x40};
//* SD card attached to SPI bus as follows:
//** MOSI - pin 11
//** MISO - pin 12
//** CLK - pin 13
//** CS - pin 10
void setup() {
// put your setup code here, to run once:
// PCD8544-compatible displays may have a different resolution...
lcd.begin(84, 48);
lcd.setContrast(40);
lcd.clear();
lcd.createChar(1, play);
lcd.createChar(2, pause);
lcd.createChar(3, stp);
//lcd.createChar(4, wait);
//lcd.createChar(5, hom);
//lcd.createChar(6, penup);
//lcd.createChar(7, pendown);
// Open serial communications and wait for port to open:
Serial.begin(115200);
mySerial.begin(57600);
pinMode(10, OUTPUT);
Serial.println(F("Init SD"));
lcd.print(F("Init SD"));
if (!SD.begin(10)) {
Serial.println(F("init fail"));
lcd.print(F("fail"));
return;
}
Serial.println(F("init done."));
//open file
myFile = SD.open("QUEUE.TXT");
if (myFile) {
fsize=myFile.size();
Serial.println(fsize);
lcd.setCursor(0, 1);
lcd.print(F("QUEUE.TXT opened"));
lcd.setCursor(0, 2);
lcd.print(fsize);lcd.println(F(" bytes"));
SDok=1;
} else {
// Π΅ΡΠ»ΠΈ ΡΠ°ΠΉΠ» Π½Π΅ ΠΎΡΠΊΡΡΠ»ΡΡ, ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ°Π΅ΠΌ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ ΠΎΠ± ΠΎΡΠΈΠ±ΠΊΠ΅:
Serial.println(F("error test.txt"));
lcd.println(F("QUEUE.TXT not found"));
}
delay(2000);
lcd.clear();
cls=1;
mode=0;
next=0;
pos=0;
}
void loop() {
if (digitalRead(A0)) ///RUN/PAUSE button
{
if (mode==2) mode=10;
if ((mode==1) && (next==0)) mode=2;
if ((mode==0)&&(SDok==1))
{
mode=1;
cls=1;
sec=0;
}
if (mode==10) mode=1;
Serial.println(F("Pressed RUN/PAUSE"));
cls=1;
delay(1000);
}
if ((digitalRead(A1)) && (next==0)) //STOP button
{
Serial.println(F("Pressed STOP"));
mode=0;
pos=0;
delay(1000);
}
/*
if (digitalRead(A2) && (mode==0)) //HOME
{
mode=3;
cls=1;
next=0;
delay(1000);
}
*/
if (mode==1)
{
if ((myFile.available())&&(next==1))
{
if (cls==1)
{
cls=0;
lcd.setCursor(0, 2);
lcd.clearLine();
lcd.setCursor(0, 1);
lcd.clearLine();
lcd.setCursor(0, 1);
myFile.seek(pos);
}
rbf=myFile.read();
mySerial.write(rbf);
lcd.write(rbf);
Serial.print(rbf);
if (rbf==10)
{
next=0;
mySerial.listen();
pos=myFile.position();
cls=2;
lcd.setCursor(0, 3);
lcd.write(4);
}
if (rbf==-1) next=0;
}
if (next==0)
{
rbs=mySerial.read(); //reading byte from polargraph serial
if (rbs>-1)
{
//display.print(rbs);
// Serial.print(char(rbs));
lcd.write(rbs);
if (cls>0) ///clear lines on screen
{
cls=0;
lcd.setCursor(0, 5);
lcd.clearLine();
lcd.setCursor(0, 4);
lcd.clearLine();
lcd.setCursor(0, 3);
lcd.clearLine();
lcd.setCursor(0, 3);
}
for (i=0;i<6;i++)
{
buff[i]=buff[i+1];
}
buff[5]=rbs;
if ((buff[5]==char(10))&& (buff[4]==char(13))) lcd.setCursor(0, 3); //End of command
if (((buff[4]=='Y') && (buff[3]=='D') && (buff[2]=='A') && (buff[1]=='E') && (buff[0]='R'))) //Ready command
{
next=1;
cls=2;
Serial.print(char(10));
if (pos==fsize) //if file is end then stop
{
mode=0;
}
}
}
}
if (millis()>now+1000) //counting time in seconds
{
now=millis();
sec=sec+1;
}
}
if ((mode==0) || (mode==2))
{
rbs=mySerial.read();
if (rbs>-1)
{
//display.print(rbs);
if (cls>0)
{
cls=0;
lcd.setCursor(0, 5);
lcd.clearLine();
lcd.setCursor(0, 4);
lcd.clearLine();
lcd.setCursor(0, 3);
lcd.clearLine();
lcd.setCursor(0, 3);
}
Serial.print(char(rbs));
lcd.write(rbs);
if (rbs==10) cls=1;
}
}
/*
if ((mode==3))
{
if (cls==1)
{
cls=0;
lcd.setCursor(0, 5);
lcd.clearLine();
lcd.setCursor(0, 4);
lcd.clearLine();
lcd.setCursor(0, 3);
lcd.clearLine();
lcd.setCursor(0, 2);
lcd.clearLine();
lcd.setCursor(0, 1);
lcd.clearLine();
lcd.setCursor(0, 1);
}
if (next==0)
{
}
}
*/
if ((cls==1)) //renew up line on screen
{
lcd.setCursor(0, 0);
//lcd.clearLine();
if (mode==1) lcd.write(1);
if (mode==2) lcd.write(2);
if (mode==0) lcd.write(3);
lcd.print(F(" "));
lcd.print(100.0*pos/fsize,2); lcd.print(F("%")); //drawing progress
lcd.print(" ");
lcd.print(sec/60); lcd.print(F("m ")); //drawing time
if (SDok==0) lcd.print(F("fail"));
//if (sec>0) lcd.print((sec*fsize/pos-sec)/60); lcd.print("m "); //remaining time
//cls=1;
}
}
|