#include #include #include #include #define OLED_RESET 12 Adafruit_SSD1306 display(OLED_RESET); #define tlinks PA15 #define tmitte PA12 #define trechts PA11 #define ter4 PA6 #define ter5 PA7 #define power PC13 //photolazer #define mess1a PA0 //optischmessstreifen Y achse #define mess1b PA1 //optischmessstreifen Y achse #define mess2a PA2 //optischmessstreifen X achse #define mess2b PA3 //optischmessstreifen X achse //endlagen #define xR PA4 //endtaster x achse rechts #define xL PA5 //endtaster x ache links #define y2 PA8 // y achse linke seite vorne links #define y1 PA7// y //module one #define m1_a PB11 //y motor links am nach hinten #define m1_b PB10 //y motor links an nach vorne #define m1_c PB1 //y motor rechts an nach hinten #define m1_d PB0 //y motor rechts an nach vorne //module two #define m2_a PC13 //stift pusher an polung - + //stift runter #define m2_b PC14 //stift pusher an polung + - //stift rauf #define m2_c PC15 // x motor an links #define m2_d PB9 // x motor an rechts //module tree #define m3_a PB12 // unused stiftkopf stepper? #define m3_b PB13 // unused stiftkopf stepper? #define m3_c PB14 // unused stiftkopf stepper? #define m3_d PB15 // unused stiftkopf stepper? uint8_t printstuff[1700]; boolean printlos=false; long tim = millis(); int zeit1 =0; int zeit2=0; int zeit3=0; int onpress[8]; void setup(){ pinMode(tlinks, INPUT); pinMode(tmitte, INPUT); pinMode(trechts, INPUT); pinMode(ter4, INPUT); pinMode(ter5, INPUT); pinMode(m1_a, OUTPUT); pinMode(m1_b, OUTPUT); pinMode(m1_c, OUTPUT); pinMode(m1_d, OUTPUT); pinMode(m2_a, OUTPUT); pinMode(m2_b, OUTPUT); pinMode(m2_c, OUTPUT); pinMode(m2_d, OUTPUT); pinMode(m3_a, OUTPUT); pinMode(m3_b, OUTPUT); pinMode(m3_c, OUTPUT); pinMode(m3_d, OUTPUT); pinMode(power, OUTPUT); Serial1.begin(115200); delay(50); /* digitalWrite(m1_a,HIGH); digitalWrite(m1_b,HIGH); digitalWrite(m1_c,HIGH); digitalWrite(m1_d,HIGH); digitalWrite(m2_a,HIGH); digitalWrite(m2_b,HIGH); digitalWrite(m2_c,HIGH); digitalWrite(m2_d,HIGH); digitalWrite(m3_a,HIGH); digitalWrite(m3_b,HIGH); digitalWrite(m3_c,HIGH); digitalWrite(m3_d,HIGH); */ digitalWrite(m1_a,LOW); digitalWrite(m1_b,LOW); digitalWrite(m1_c,LOW); digitalWrite(m1_d,LOW); digitalWrite(m2_a,LOW); digitalWrite(m2_b,LOW); digitalWrite(m2_c,LOW); digitalWrite(m2_d,LOW); digitalWrite(m3_a,LOW); digitalWrite(m3_b,LOW); digitalWrite(m3_c,LOW); digitalWrite(m3_d,LOW); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) display.clearDisplay(); } void loop(){ bedien(); zeitreise(); if (zeit2 >10) {zeit2=0;} schaltleds(); communicate(); } int welch=0; int stepi=0; int istm1=0; int istm2=0; int istm3=0; int istm4=0; int way1=0; //y weg int way2=0; //x weg int hole1=10; int hole2=80; long ka=0; int step2 =0; int isty=0; boolean zeropos=false; void bedien(void) { if (zeit1 >=1) { if (digitalRead(tlinks) == HIGH && onpress[0] ==0) { onpress[0] =1; zeigzeugs();} //minisound if (onpress[0] == 1) { onpress[1]++;} if (onpress[1] >= 10) { onpress[1] =0; onpress[0]=0;} if (digitalRead(tmitte) == HIGH && onpress[2] ==0) { onpress[2] =1;Serial1.print("MEOW");} if (onpress[2] == 1) { onpress[3]++;} if (onpress[3] >= 10) { onpress[3] =0; onpress[2]=0; } if (digitalRead(trechts) == HIGH && onpress[4] ==0) { onpress[4] =1; zeropos=true; step2=0; isty=0; getstartpos();} if (onpress[4] == 1) { onpress[5]++;} if (onpress[5] >= 13) { onpress[5] =0; onpress[4]=0;} zeit1=0;} if(welch >8) {welch=0;} if(stepi >=2) {stepi=0;} } void zeigzeugs2(){ display.clearDisplay(); display.setTextColor(WHITE); display.setCursor(0,0); display.setTextSize(4); display.print("READY"); display.display();} void zeigzeugs(){ display.clearDisplay(); display.setTextColor(WHITE); display.setCursor(0,0); display.setTextSize(2); display.print("READY"); display.setCursor(0,15); //display.print(hole1); //display.print("PA6:"); display.print(istm4); display.setTextSize(2); display.print("WEG:"); display.print(way1); display.setCursor(0,48); display.print("WEG:"); display.print(way2); display.display(); } int motornachf=0; void zeitreise(void){ while ((millis()- tim) >= 50) { zeit1++; zeit2++; //motornachf++; tim = millis(); } } int leds=0; int ledcach=0; void schaltleds() { } int merks=0; int merks2=0; void readmessiy(int how){ istm1= analogRead(mess1a); istm2= analogRead(mess1b); if ((istm1) > (istm2+hole2) && merks==0 && how ==1) {way1++; merks=1; } if ((istm1) > (istm2+hole2) && merks==0 && how ==0) {way1--; merks=1; } if ((istm1) < (istm2+hole1) && merks==1 ) {merks=0;} } void readmessix(int how2){ istm3= analogRead(mess2a); istm4= analogRead(mess2b); if ((istm3) > (istm4+500) && merks2==0 && how2 ==1) {way2++; merks2=1; } if ((istm3) > (istm4+500) && merks2==0 && how2 ==0) {way2--; merks2=1; } if ((istm3) < (istm4+500) && merks2==1) {merks2=0;} } boolean daax=false; boolean daay=false; boolean neboo=false; boolean nenboo=false; int richtung =0; int richtung2 =0; int motornachlauf=100; //warten bis gestoppt // 0vorne links //1 hinten rechts void movetox(int target) { if (target < way2) {richtung =0;} if (target > way2) {richtung =1;} readmessix(richtung); if (richtung == 1) { if (target > way2) {digitalWrite(m2_d,HIGH);daax =false;} //rechts if (target <= way2) {digitalWrite(m2_d,LOW); daax =true;} } if (richtung == 0) { if (target < way2) {digitalWrite(m2_c,HIGH);daax =false;} //links if (target >= way2) {digitalWrite(m2_c,LOW); daax =true;} } } void movetoy(int target2) { if (target2 < way1) {richtung2 =0;} if (target2 > way1) {richtung2 =1;} readmessiy(richtung2); if (richtung2 == 1) { if (target2 > way1) {digitalWrite(m1_a,HIGH);digitalWrite(m1_c,HIGH); daay=false;} //hinten if (target2 <= way1) {digitalWrite(m1_a,LOW); digitalWrite(m1_c,LOW); daay=true;}} if (richtung2 == 0) { if (target2 < way1) {digitalWrite(m1_b,HIGH);digitalWrite(m1_d,HIGH); daay=false;;} //vorne if (target2 >= way1) {digitalWrite(m1_b,LOW); digitalWrite(m1_d,LOW); daay=true;}} } void getstartpos(void){ while (zeropos == true) { if (step2 ==0) { digitalWrite(m2_b,HIGH); if (digitalRead(y1) ==LOW) {digitalWrite(m1_b,HIGH);} if (digitalRead(y1) ==HIGH){digitalWrite(m1_b,LOW);} if (digitalRead(y2) ==LOW) {digitalWrite(m1_d,HIGH);} if (digitalRead(y2) ==HIGH){digitalWrite(m1_d,LOW);} if (digitalRead(xL) ==LOW) {digitalWrite(m2_c,HIGH);} if (digitalRead(xL) ==HIGH){digitalWrite(m2_c,LOW);} if (digitalRead(y1) ==HIGH && digitalRead(y2) ==HIGH && digitalRead(xL) ==HIGH){ digitalWrite(m2_b,LOW); delay(100); way1=0; way2=0; step2=1;}} if (step2 ==1 ) {movetox(100); } if (step2 ==1 && daax ==true) {step2=2;} if (step2 ==2 ) {movetoy(100);} if (step2 ==2 && daay ==true) {step2=3;} if (step2 ==3) {way1=0; way2=0; digitalWrite(m2_b,LOW); zeigzeugs2(); delay(100);zeropos=false;} }} String was=""; String data=""; String wasdata=""; int width=0; int posx=0; String cachs2=""; String washdata=""; boolean printdata =false; int richtungs =0; boolean loss=false; boolean nexthoch =false; int posyy=0; int steppp=0; void communicate(void) { int cachs2 = Serial1.read(); if ((char)cachs2 == 'p'){was=""; data="";wasdata=""; loss=true;} while(loss ==true ) { int cachs = Serial1.read(); was=""; data=""; was += (char)cachs; data += (char)cachs; if (isDigit(cachs)) {wasdata +=(char)cachs; } if (isDigit(cachs) && nexthoch ==true) {washdata +=(char)cachs;} if (nexthoch ==false) {washdata="";} if ( was == "w" ) { //setze breite width= wasdata.toInt(); wasdata== ""; nexthoch=true; data=""; was=""; } if ( was == "h" ) { //setze hoehe derzeile posyy= washdata.toInt(); nexthoch=false; wasdata== ""; data=""; was=""; } if ( data == "-") { printstuff[posx]=0; data=""; posx++; } if (data == "#"){ printstuff[posx]=1; data=""; posx++; } if ( was == "d") { posx=0; richtungs=0; steppp=0; printlos=true; loss=false; } if ( was == "i") { display.clearDisplay(); display.setCursor(0,0); display.setTextSize(4); display.setTextColor(WHITE); display.print("MEOW"); display.display(); loss=false; } if ( was == "a") { isty=0; }} if (printlos == true) { if(steppp ==0) {movetox(width);} if (printstuff[way2] == 1) { digitalWrite(m2_a,HIGH); } if (printstuff[way2] == 0) {digitalWrite(m2_a,LOW);} if (daax == true && steppp==0) { digitalWrite(m2_a,LOW); steppp=1; } if (steppp==1) { movetoy(posyy); } if (daay == true && steppp==1) { steppp=2; } if (steppp==2) { movetox(0); } if (daax == true && steppp==2 ) {Serial1.print("n"); steppp=0; printlos=false; } } } //programm for drifing (currently pencil using) plotter.. x achse can be set movetox(1234); for move to xposition 1234 on sheep.. y movetoy(1234); same, if achse have reached daax or daay is setet true.. //it received character "-" for nonepoint pencil on paper and "#" for pencil on paper.. together with line length and position of the x line in one transmition and gife "n" back if line printet and ready for next.. // have 3 keys on printer right get zero position (x and y is setet to zero 100points left from end of position taster), middle send "MEOW" to serial to prove connection // on the head are 3x on/off/refersepoles 2wires connections aviable and one unused meassure wire.. currently 1 of the 2phase connections used for the harddisk headmover pencil pusher.. // MEOW now can print UV pencil pictures (working on powerful 3phase engine and maybe a lightning do do art on other materials.. but first have to optimize speeds (the voltage for engines/pusher can be settzer from 5-33Volt //by changing adjustable step-up the serial transmition datarete is 115200 baud, the software forwarding TCP port (127.0.0.1:8000) from my fash to serial com1<->ttl<->rs232 level converter=->STM32F103C8T6) is the freeware COMbyTCP //its fun cant stop wathcing moving.. *purrrr* //i know the code solution for driving my selfcreatet plotter/somthingelse devise is not the best maybe i get some ides sometime to optimize it (would send 0 and 1 over TCP but forrwarding software says its int32and not Byte port and cut connection so have to use - and #) //but its working fine (with little errors sometimes) //MEOW! its free use it or parts if there is somethink usefull for you //code by marderchen =^.^= watch coutubevideo for funtionview