|
Post by bigbass on Jan 15, 2019 16:31:08 GMT 1
hey guys I showed a programming way to connect using FTDI and the USB to usb mini cable connected to an aruino in the prior post there is a lot you can do with that and having the baconized ported code for FTDI will make it much easier now to expand on In this post we will just use the raspberry pi3 alone and its on board gpio pins this is the easiest way to test with to confirm the gpio pins are sending and receiving data wiki.protoneer.co.nz/Raspberry_Pi_Serial_TroubleShootingwiki.protoneer.co.nz/images/9/97/Raspberry-Pi-GPIO-Layout-Model-B-Plus-rotated.pngI confirmed that link here is a screen shot from my raspberry pi3 using minicom Notice I used /dev/serial0 this way I know I am using the pi's GPIO pins for TXD and RXD *so as not to confuse things with the arduino's connection to the pi using a standard USB to usb mini cable one part is hardware we need to connect to different hardware out there one part is software this is where I want to communicate using bacon but there many pre-steps to sort out and confirm that all will work correctly Joe
|
|
|
Post by bigbass on Jan 17, 2019 18:51:39 GMT 1
hey guys This is for anyone using a FTDI connection www.ftdichip.com/USB.htmlI just happen to be using the on board built in connection (no special cable is used ) on the arduino nano but any FTDI chip would be detected because it is using the official library I combined the two official demos simple.c and find_all.c together and ported it to bacon github.com/legege/libftdi/blob/master/examples/find_all.cthe result of running the code is a great help when you want to be sure if you are connected and if you want to communicate with that device P.S this works in c++ also without having to include the monster libboost! sudo ./findall2 Initialized libftdi 1.3 FTDI chipid: 81A8C35D Number of FTDI devices found: 1 Manufacturer: FTDI Description: FT232R USB UART Joe '--- ported the official find_all.c demo to bacon by bigbass '--- the ftdi header is included so that no conversion errors are generated '--- when doing the low level serial communication in c or c++
PRAGMA INCLUDE <libftdi1/ftdi.h> PRAGMA LDFLAGS -lftdi1 -lftdi ' if you want to comile in c++ uncomment the next two lines 'PRAGMA LDFLAGS -lbacon++ -s 'PRAGMA COMPILER g++ PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wformat=0 OPTION PARSE FALSE
DECLARE ret , i TYPE int DECLARE ftdi TYPE struct ftdi_context* DECLARE version TYPE struct ftdi_version_info DECLARE devlist TYPE struct ftdi_device_list* DECLARE curdev TYPE struct ftdi_device_list* DECLARE manufacturer[128] TYPE char DECLARE description[128] TYPE char
ftdi = ftdi_new() IF (ftdi == 0) THEN PRINT "ftdi_init failed" END 1 END IF
version = ftdi_get_library_version() PRINT "Initialized libftdi" ,version.version_str FORMAT "%s %s\n" ret = ftdi_usb_open(ftdi, 0x0403, 0x6001) IF (ret < 0) THEN PRINT "unable to open ftdi device:" ,ftdi_get_error_string(ftdi) FORMAT "%s %s\n" ftdi_free(ftdi) END 1 END IF
'--- Read out FTDIChip-ID of R type chips IF (ftdi->type == TYPE_R) THEN DECLARE chipid TYPE unsigned int ftdi_read_chipid(ftdi, &chipid) '--- there was no error message on fail will add a condition IF ftdi_read_chipid(ftdi, &chipid) != 0 THEN PRINT "reading ftdi_read_chipid() failed" ELSE PRINT "FTDI chipid: " , chipid FORMAT "%s %X\n" END IF END IF IF ((ret = ftdi_usb_close(ftdi)) < 0) THEN PRINT "unable to close ftdi device:" ftdi_free(ftdi) END 1 END IF '--- add the ftdi_usb_find_all example ret = ftdi_usb_find_all(ftdi, &devlist, 0, 0) IF (ret < 0) THEN PRINT "ftdi_usb_find_all failed:" ,ftdi_get_error_string(ftdi) FORMAT "%s %s\n" END 1 END IF PRINT "Number of FTDI devices found: ", ret i = 0 curdev = devlist WHILE curdev != NULL ret2 = ftdi_usb_get_strings(ftdi, curdev->dev, manufacturer, 128, description, 128, NULL, 0)
IF (ret2 < 0) THEN PRINT "ftdi_usb_get_strings failed:" ,ftdi_get_error_string(ftdi) FORMAT "%s %s\n" END IF PRINT "Manufacturer: " ,manufacturer FORMAT "%s %s\n" PRINT "Description:" , description FORMAT "%s %s\n" curdev = curdev->next
WEND '---memory cleanup ftdi_list_free(&devlist) ftdi_free(ftdi)
|
|
|
Post by bigbass on Jan 21, 2019 10:12:45 GMT 1
If you want to go around using python or C to send logic to the GPIO pins on the raspberry pi3 you could do it in just bacon and some system calls
this is a simple test of a four wire stepper motor I will make a nice include file to keep it simple and clean I manually figured out the code here we used GPIO PINS 17,22,23,24
OPTION PARSE FALSE
SUB CLEANUP1() '--- we need to clean up memory and disable the pins EXEC$(" echo 0 > /sys/class/gpio/gpio17/value") EXEC$(" echo 0 > /sys/class/gpio/gpio22/value") EXEC$(" echo 0 > /sys/class/gpio/gpio23/value") EXEC$(" echo 0 > /sys/class/gpio/gpio24/value") EXEC$(" echo 17 > /sys/class/gpio/unexport") EXEC$(" echo 22 > /sys/class/gpio/unexport") EXEC$(" echo 23 > /sys/class/gpio/unexport") EXEC$(" echo 24 > /sys/class/gpio/unexport") END SUB
'--- create the port initialize only once '--- set output type in or out EXEC$("echo 17 > /sys/class/gpio/export") EXEC$(" echo out > /sys/class/gpio/gpio17/direction")
EXEC$("echo 22 > /sys/class/gpio/export") EXEC$(" echo out > /sys/class/gpio/gpio22/direction")
EXEC$("echo 23 > /sys/class/gpio/export") EXEC$(" echo out > /sys/class/gpio/gpio23/direction")
EXEC$("echo 24 > /sys/class/gpio/export") EXEC$(" echo out > /sys/class/gpio/gpio24/direction") SUB STEPPERMOTOR1() EXEC$(" echo 1 > /sys/class/gpio/gpio17/value") SLEEP TIMEVALUE1 EXEC$(" echo 0 > /sys/class/gpio/gpio17/value") EXEC$(" echo 1 > /sys/class/gpio/gpio22/value") SLEEP TIMEVALUE1 EXEC$(" echo 0 > /sys/class/gpio/gpio22/value") EXEC$(" echo 1 > /sys/class/gpio/gpio23/value") SLEEP TIMEVALUE1 EXEC$(" echo 0 > /sys/class/gpio/gpio23/value") EXEC$(" echo 1 > /sys/class/gpio/gpio24/value") SLEEP TIMEVALUE1 EXEC$(" echo 0 > /sys/class/gpio/gpio24/value") END SUB
'--- the simple users code if I make an include stepper.bac
TIMEVALUE1 = 1000
FOR i = 1 TO 5 STEPPERMOTOR1 NEXT
CLEANUP1
|
|
|
Post by bigbass on Jan 27, 2019 5:02:30 GMT 1
Hey guys I read though many pages of code and when you dont find an easy answer make a new road I solved a complex problem (GPIO used as interrupts) an easy way but its better to go in steps objective : a better way than polling hardware events using inotify-tools A great way to debug events (as files) www.infoq.com/articles/inotify-linux-file-system-event-monitoring# on a debian based system sudo apt-get install inotify-tools first step make some test directory in tmp This is run in a terminal (first terminal) setup the fake interrupt looking for any changes to the file /tmp/test second terminal but watching the output in the first terminal here is the updated result after sending the command I am already using this another way to follow GPIO pins and have interrupts working ! but it is easier to explain with this demo here is a simple demo # objective : a better way than polling events # I want to use this as a way to track events like an interrupt would do # when using hardware but using the the filesytem to keep track of changes
#The original post that shows how to follow files ( a great insight ) #https://www.infoq.com/articles/inotify-linux-file-system-event-monitoring
# GOAL: To use the GPIO pins and fake an interrupt without having to poll # this is an odd way of doing it but it seems the easiest way to me # without using C or Python or some other low level hardware lib # I thought to take it a different direction to watch hardware changes
#prestep install inotify-tools its very small in size
# on a debian based system #sudo apt-get install inotify-tools #inotify-tools - command-line programs providing a simple interface to inotify
# first step make some test directory in tmp mkdir /tmp/test
This is run in one terminal (first terminal) # setup the fake interrupt looking for any changes to the file /tmp/test inotifywait -me modify,attrib,move,close_write,create,delete,delete_self /tmp/test
This is run in a second terminal watching the first terminal for changes #WRITE echo out > /tmp/test/direction
#READ cat /tmp/test/direction
#REMOVE clean up rm /tmp/test/direction rmdir /tmp/test
# you can ctrl-c to break out if needed
|
|
|
Post by bigbass on Jan 27, 2019 19:26:39 GMT 1
Hello Rik In another previous post you suggested a command line for serial and then use tail in another terminal for many arduino projects that would be the correct way but I am using grbl which is code to convert gcode to stepper motor movement and tail doesn't work and I couldn't find any documentation to use the command line with grbl the setting up the serial port is the same code for the arduino nano this is the standard connection but note baud 115200 and /dev/ttyUSB0 are needed for the grbl code to communicate stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
where the change takes place is here by using catopen a new terminal and cat /dev/ttyUSB0 then in the first terminal which ran the serial setup run the $ char is a special command that communicates with grbl this allows for manual configuration changes or changing motor speeds or to move a motor x y z from the command line overriding the reading of the input file echo $ > /dev/ttyUSB0 now I can send code to the arduino nano will attach some screen shots because I couldnt find any demos using pure command line connecting to the grbl code on the microcontroller if you notice something here I dont need to reburn /upload code to the arduino or use avrdude I can send code to the nano manually though the serial connection and I dont need to use any sketch this way I can run a 3 axis contoller in real time manually talking to the micro controller a great way to control robotics too! the best part is I don't need to upload any new code to the arduino (ever)grbl is now the "onboard OS" taking commands directly no wirinPi no python no C or C++ no sketches no external libs and it is a precision controller Joe
|
|
|
Post by rikky on Jan 28, 2019 8:39:41 GMT 1
Thanks Joe, This is usefull information. Except, I am not that quickly I am currently in the process of making a timer on a light switch, with a webpage :-) (Arduino + ethernet shield) Which is difficult enough. CNC has to wait. As I understand it can be used also for any machine with stepper motors, so ja, It has to wait, but will eventually come on the table, if I progress enough. Thanks Rik.
|
|
|
Post by rikky on Jan 28, 2019 21:55:20 GMT 1
In BaCon language it would be someting like: ROLLON(parameters, directions etc) and ROLLOFF(parameters, directions etc) I suppose. Rik.
|
|
|
Post by bigbass on Jan 29, 2019 18:01:08 GMT 1
Hey Guys I haven't forgotten BaCon I just needed to confirm for sure all will connect with using C and bash first and have some solid reference to verify the output once ported to BaCon after that testing here is the BaCon way ! there is an old post from 2011 that has great info how to go about this in BaCon basic-converter.proboards.com/thread/95/ftdi-support-puppy-linuxI could not start there without getting it to work first using the standard linux tools now that I see it works the porting part is easier now READ
'run this first and keep it open 'after you can write to the device OPEN "/dev/ttyUSB0" FOR READING AS arduino WHILE TRUE READLN txt$ FROM arduino IF LEN(txt$) > 0 THEN PRINT txt$ SLEEP 10 WEND
WRITE OPEN "/dev/ttyUSB0" FOR WRITING AS arduino 'WHILE TRUE txt$ = "$$" WRITELN txt$ TO arduino IF LEN(txt$) > 0 THEN PRINT txt$ SLEEP 10 'WEND
note for easy testing use bCNC linux software in python first it has a GUI and works on the raspberrypi correctly ====advanced use====================================== ====================================================== this is an extra bonus here is how you can send real gcode if you want to use grbl on an arduino and pulse stepper motors manually (using bacon) to verify all the connections to the motors before doing real cutting or moving of the steppermotors '---https://www.cnccookbook.com/g91-g90-g-code-cnc-absolute-incremental-programming/
OPEN "/dev/ttyUSB0" FOR WRITING AS arduino '---WHILE TRUE
'--- just test if grbl is connected no movements 'txt$ = "$$"
'--- if you want to run real gcode txt$ = "G91 G0 X1"
WRITELN txt$ TO arduino IF LEN(txt$) > 0 THEN PRINT txt$ SLEEP 10 '--- THIS IS OFFICIAL GCODE '--- G91 G0 X1 '--- translated means move the X steppermotor one milimeter to '--- right from the last position you were (Incremental Programming) '--- I just sent one pulse to the arduino on GPIO2 the Xstep pulse '--- I connected a LED to GPIO2 to verify the pulse '--- note GPIO2 is on the arduino not the RPI '---WEND
|
|
|
Post by bigbass on Jan 31, 2019 18:26:40 GMT 1
Hey guys here is a small GUI for the serial port you can send data from the GUI command line input I needed to test some ideas and I couldn't see myself making a GUI in fltk then gluing it together with python scripts sorry... almost everything for the raspberry pi is in python we can change that though with a few things written in BaCon P.S I will add in the xyz stepper code later but the GUI part is done Joe '--- GUI for serial port connection '--- you can write commands from the command line '--- to verify you can open another terminal cat /dev/ttyUSB0 '--- by bigbass
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Light_Button.H> PRAGMA INCLUDE <FL/Fl_File_Browser.H> PRAGMA INCLUDE <FL/Fl_Input.H>
PRAGMA LDFLAGS -lfltk -L. 'PRAGMA LDFLAGS -lbacon++ PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wno-permissive OPTION PARSE FALSE
DECLARE CONNECT TYPE Fl_Light_Button* DECLARE BOX2 TYPE Fl_Box* DECLARE OUTPUT TYPE Fl_File_Browser* DECLARE BOX1 TYPE Fl_Box* DECLARE COMMANDLINE TYPE Fl_Input* DECLARE PORT TYPE Fl_Input* DECLARE BAUDRATE TYPE Fl_Input* DECLARE YPOS TYPE Fl_Button* DECLARE XPOS TYPE Fl_Button* DECLARE XNEG TYPE Fl_Button* DECLARE YNEG TYPE Fl_Button* DECLARE ZNEG TYPE Fl_Button* DECLARE ZPOS TYPE Fl_Button* DECLARE WINDOW TYPE Fl_Double_Window*
DECLARE porttext TYPE STRING DECLARE baudratetext TYPE STRING
SUB YPOS_CB(Fl_Widget* dummy, void* data) PRINT "YPOS" OUTPUT->add(dummy->label()) END SUB
SUB XPOS_CB(Fl_Widget* dummy, void* data) PRINT "XPOS" OUTPUT->add(dummy->label()) END SUB
SUB XNEG_CB(Fl_Widget* dummy, void* data) PRINT "XNEG" OUTPUT->add(dummy->label()) END SUB
SUB YNEG_CB(Fl_Widget* dummy, void* data) PRINT "YNEG" OUTPUT->add(dummy->label()) END SUB
SUB ZNEG_CB(Fl_Widget* dummy, void* data) PRINT "ZNEG" OUTPUT->add(dummy->label()) END SUB
SUB ZPOS_CB(Fl_Widget* dummy, void* data) PRINT "ZPOS" OUTPUT->add(dummy->label()) END SUB
SUB COMMANDLINE_CB(Fl_Widget* dummy, void* data) PRINT "Command line" DECLARE commandlinetext TYPE STRING commandlinetext$ = COMMANDLINE->value() OUTPUT->add( commandlinetext$ ) OPEN "/dev/ttyUSB0" FOR READWRITE AS arduino WRITELN commandlinetext$ TO arduino IF LEN(commandlinetext$) > 0 THEN PRINT commandlinetext$ SLEEP 50 CLOSE FILE arduino END SUB
SUB CONNECT_CB(Fl_Widget* dummy, void* data) PRINT "connect" porttext$ = PORT->value() OUTPUT->add( porttext$ ) SETENVIRON "PORTTEXT",porttext$ baudratetext$ = BAUDRATE->value() OUTPUT->add( baudratetext$ ) SETENVIRON "BUADRATETEXT", baudratetext$
EXEC$("stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts") PRINT porttext$ , baudratetext$ END SUB
SUB PORT_CB(Fl_Widget* dummy, void* data) PRINT "Port" END SUB
SUB BAUD_CB(Fl_Widget* dummy, void* data) PRINT "baud" END SUB
WINDOW = new Fl_Double_Window(460, 520, "GERBL / GCODE Controller") WINDOW->box(FL_GLEAM_DOWN_BOX) WINDOW->color((Fl_Color)14) YPOS = new Fl_Button(73, 433, 45, 50, "Y") YPOS->tooltip("moves toward the front of the machine") YPOS->box(FL_GLEAM_ROUND_DOWN_BOX) YPOS->color((Fl_Color)221) YPOS->labelcolor((Fl_Color)55) YPOS->callback((Fl_Callback*)YPOS_CB)
XPOS = new Fl_Button(118, 385, 45, 50, "X") XPOS->tooltip("Moves toward the right of the machine") XPOS->box(FL_GLEAM_ROUND_DOWN_BOX) XPOS->color((Fl_Color)181) XPOS->labelcolor((Fl_Color)55) XPOS->callback((Fl_Callback*)XPOS_CB) XNEG = new Fl_Button(28, 385, 45, 50, "X-") XNEG->tooltip("Moves toward the left of the machine") XNEG->box(FL_GLEAM_ROUND_DOWN_BOX) XNEG->color((Fl_Color)181) XNEG->labelcolor((Fl_Color)55) XNEG->callback((Fl_Callback*)XNEG_CB) YNEG = new Fl_Button(73, 336, 45, 50, "Y-") YNEG->tooltip("Moves toward the back of the machine") YNEG->box(FL_GLEAM_ROUND_DOWN_BOX) YNEG->color((Fl_Color)221) YNEG->labelcolor((Fl_Color)55) YNEG->callback((Fl_Callback*)YNEG_CB)
ZNEG = new Fl_Button(193, 375, 45, 50, "Z-") ZNEG->tooltip("Moves the cutter up") ZNEG->box(FL_GLEAM_ROUND_DOWN_BOX) ZNEG->color((Fl_Color)198) ZNEG->callback((Fl_Callback*)ZNEG_CB) ZPOS = new Fl_Button(193, 435, 45, 50, "Z") ZPOS->tooltip("Moves the cutter down") ZPOS->box(FL_GLEAM_ROUND_DOWN_BOX) ZPOS->color((Fl_Color)198) ZPOS->callback((Fl_Callback*)ZPOS_CB) BOX1 = new Fl_Box(10, 326, 245, 177) BOX1->box(FL_GLEAM_DOWN_FRAME) BOX1->color((Fl_Color)33) BOX1->labelsize(24) COMMANDLINE = new Fl_Input(10, 251, 245, 47, "Command Line") COMMANDLINE->tooltip("Excepts gcode and grbl commands") COMMANDLINE->box(FL_GLEAM_ROUND_DOWN_BOX) COMMANDLINE->callback((Fl_Callback*)COMMANDLINE_CB) COMMANDLINE->align(Fl_Align(FL_ALIGN_TOP_LEFT)) PORT = new Fl_Input(59, 49, 158, 30, "Port: ") PORT->tooltip("The full path of the serial device /dev/ttyUSB0") PORT->box(FL_GLEAM_ROUND_DOWN_BOX) PORT->callback((Fl_Callback*)PORT_CB) PORT->value("/dev/ttyUSB0") BAUDRATE = new Fl_Input(58, 94, 160, 30, "Baud:") BAUDRATE->tooltip("grbl needs 115200 but you can use 2400,4800,9600,19200,38400,57600") BAUDRATE->box(FL_GLEAM_ROUND_DOWN_BOX) BAUDRATE->callback((Fl_Callback*)BAUD_CB) BAUDRATE->value("115200") CONNECT = new Fl_Light_Button(58, 139, 160, 47, "Connect") CONNECT->tooltip("Opens port or closes port the led displays status") CONNECT->box(FL_GLEAM_ROUND_DOWN_BOX) CONNECT->color((Fl_Color)197) CONNECT->callback((Fl_Callback*)CONNECT_CB) BOX2 = new Fl_Box(10, 32, 245, 171, "Serial") BOX2->box(FL_GLEAM_DOWN_FRAME) BOX2->color(FL_FOREGROUND_COLOR) BOX2->selection_color((Fl_Color)43) BOX2->labelsize(24) BOX2->align(Fl_Align(FL_ALIGN_TOP_LEFT))
OUTPUT = new Fl_File_Browser(265, 32, 175, 471) OUTPUT->box(FL_GLEAM_ROUND_DOWN_BOX)
WINDOW->end() WINDOW->show(argc, argv) Fl::run()
|
|
|
Post by rikky on Feb 1, 2019 15:54:01 GMT 1
The IDE works nice,no problem there. But I tried to get the serial communications part to no avail. I have : usb_port$ = "/dev/ttyACM0" baudrate$ = "115200" SYSTEM "stty -F " & usb_port$ & " cs8 " & baudrate$ & " ignbrk " & \ "-brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten " & \ "-echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts" INPUT "sendtext : ", sendtext$ OPEN usb_port$ FOR READWRITE AS arduino WRITELN sendtext$ TO arduino IF LEN(sendtext$) > 0 THEN PRINT "send : " & sendtext$ SLEEP 50 CLOSE FILE arduino
On the arduino I have this scetch: Serial Event example
When new serial data arrives, this sketch adds it to a String. When a newline is received, the loop prints the string and clears it.
A good test for this is to try it with a GPS receiver that sends out NMEA 0183 sentences.
NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or other ATmega32U4 based boards.
created 9 May 2011 by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialEvent */
String inputString = ""; // a String to hold incoming data bool stringComplete = false; // whether the string is complete
void setup() { // initialize serial: Serial.begin(115200); // reserve 200 bytes for the inputString: inputString.reserve(200); }
void loop() { // print the string when a newline arrives: if (stringComplete) { Serial.print("recieved : "); Serial.println(inputString); // clear the string: inputString = ""; stringComplete = false; } }
/* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag so the main loop can // do something about it: if (inChar == '\n') { stringComplete = true; } } } I open another console and type: tail -f /dev/ttyACM0
(cat doesn't seem to work without grbl) Now I can send whatever I like in my BaCon send program, but I receive nothing. Cntrl C and then echo "something" > /dev/ttyACM0 And hops, I receive recieved : something I guess grbl is doing differently then serial write. hmm, I figure it out.... Rik.
|
|
|
Post by alexfish on Feb 1, 2019 19:48:36 GMT 1
Hi Rik
only observing , it been a while since using two terminals with serial devices
here thinking 'the cat terminal <receiving> , should this be opened first' , or does it matter
BR Alex
|
|
|
Post by bigbass on Feb 2, 2019 7:18:02 GMT 1
Hey Guys Rik you have a syntax error in SYSTEM take a look at this snippet below that should clear it up if you want to test in sketch I suggest from the sketch GUI Tools--->Serial Monitor---> then there is a drop down box where you could change to carriage returnor test newline if that doesnt work here is a screen shot of sketch ------------------------------------ I fixed the hard coded values to use editable values from the GUI SETENVIRON did the job now you can change baudrates and dev I also figured a way to simulate opening another terminal and get the output into the GUI without cat this was a real pain to do but it works finally fltk still has that ^M problem in the display I'll fix that tomorrow one problem still is it delimits at space and I need NL$ to be the split for this it cuts my output anyway many improvements to try and see if this will work for other serial connections now I see why we have a problem there is no endfile marker so I put a read 10 limit '--- GUI for serial port connection '--- you can write commands from the command line '--- to verify you can open another terminal cat /dev/ttyUSB0 '--- by bigbass SETENVIRON "LC_ALL", "C" PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Light_Button.H> PRAGMA INCLUDE <FL/Fl_File_Browser.H> PRAGMA INCLUDE <FL/Fl_Input.H> PRAGMA INCLUDE <stdlib.h> PRAGMA INCLUDE <string.h>
PRAGMA LDFLAGS -lfltk -L. 'PRAGMA LDFLAGS -lbacon++ PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fpermissive OPTION PARSE FALSE
DECLARE CONNECT TYPE Fl_Light_Button* DECLARE BOX2 TYPE Fl_Box* DECLARE OUTPUT TYPE Fl_File_Browser* DECLARE BOX1 TYPE Fl_Box* DECLARE COMMANDLINE TYPE Fl_Input* DECLARE PORT TYPE Fl_Input* DECLARE BAUDRATE TYPE Fl_Input* DECLARE YPOS TYPE Fl_Button* DECLARE XPOS TYPE Fl_Button* DECLARE XNEG TYPE Fl_Button* DECLARE YNEG TYPE Fl_Button* DECLARE ZNEG TYPE Fl_Button* DECLARE ZPOS TYPE Fl_Button* DECLARE WINDOW TYPE Fl_Double_Window*
DECLARE porttext$ TYPE STRING DECLARE baudratetext$ TYPE STRING
SUB YPOS_CB(Fl_Widget* dummy, void* data) PRINT "YPOS" OUTPUT->add(dummy->label()) END SUB
SUB XPOS_CB(Fl_Widget* dummy, void* data) PRINT "XPOS" OUTPUT->add(dummy->label()) END SUB
SUB XNEG_CB(Fl_Widget* dummy, void* data) PRINT "XNEG" OUTPUT->add(dummy->label()) END SUB
SUB YNEG_CB(Fl_Widget* dummy, void* data) PRINT "YNEG" OUTPUT->add(dummy->label()) END SUB
SUB ZNEG_CB(Fl_Widget* dummy, void* data) PRINT "ZNEG" OUTPUT->add(dummy->label()) END SUB
SUB ZPOS_CB(Fl_Widget* dummy, void* data) PRINT "ZPOS" OUTPUT->add(dummy->label()) END SUB
SUB COMMANDLINE_CB(Fl_Widget* dummy, void* data) PRINT "Command line" LOCAL $commandlinetext TYPE STRING commandlinetext$ = COMMANDLINE->value() OUTPUT->add( commandlinetext$ ) LIMITLOOP = 10 '---run this first and keep it open for a set number of readlines '---after you can write to the device OPTION DELIM NL$ OPEN porttext$ FOR READWRITE AS arduino
WHILE LIMITLOOP > 0 READLN txt$ FROM arduino IF LEN(txt$) > 0 THEN OUTPUT->add( txt$ ) txt$ = EXTRACT$(txt$, "\015") txt$ = EXTRACT$(txt$, "\r\n") PRINT txt$ DECR LIMITLOOP SLEEP 20 END IF '---then write and clean up inputbox to make sure we dont repeat it OPEN porttext$ FOR READWRITE AS arduino WRITELN commandlinetext$ TO arduino IF LEN(commandlinetext$) > 0 THEN PRINT commandlinetext$ SLEEP 10 COMMANDLINE->value("") END IF WEND CLOSE FILE arduino END SUB
SUB CONNECT_CB(Fl_Widget* dummy, void* data) PRINT "connect" porttext$ = PORT->value() OUTPUT->add( porttext$ ) SETENVIRON "PORTTEXT",porttext$ baudratetext$ = BAUDRATE->value() OUTPUT->add( baudratetext$ ) SETENVIRON "BAUDRATETEXT",baudratetext$ SYSTEM(" stty -F \"$PORTTEXT\" cs8 \"$BAUDRATETEXT\" ignbrk \ -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo \ -echoe -echok -echoctl -echoke noflsh -ixon -crtscts") PRINT "you are using ", porttext$ ," ", baudratetext$ END SUB
SUB PORT_CB(Fl_Widget* dummy, void* data) PRINT "Port" END SUB
SUB BAUD_CB(Fl_Widget* dummy, void* data) PRINT "baud" END SUB
WINDOW = new Fl_Double_Window(460, 520, "GERBL / GCODE Controller") WINDOW->box(FL_GLEAM_DOWN_BOX) WINDOW->color((Fl_Color)14) YPOS = new Fl_Button(73, 433, 45, 50, "Y") YPOS->tooltip("moves toward the front of the machine") YPOS->box(FL_GLEAM_ROUND_DOWN_BOX) YPOS->color((Fl_Color)221) YPOS->labelcolor((Fl_Color)55) YPOS->callback((Fl_Callback*)YPOS_CB)
XPOS = new Fl_Button(118, 385, 45, 50, "X") XPOS->tooltip("Moves toward the right of the machine") XPOS->box(FL_GLEAM_ROUND_DOWN_BOX) XPOS->color((Fl_Color)181) XPOS->labelcolor((Fl_Color)55) XPOS->callback((Fl_Callback*)XPOS_CB) XNEG = new Fl_Button(28, 385, 45, 50, "X-") XNEG->tooltip("Moves toward the left of the machine") XNEG->box(FL_GLEAM_ROUND_DOWN_BOX) XNEG->color((Fl_Color)181) XNEG->labelcolor((Fl_Color)55) XNEG->callback((Fl_Callback*)XNEG_CB) YNEG = new Fl_Button(73, 336, 45, 50, "Y-") YNEG->tooltip("Moves toward the back of the machine") YNEG->box(FL_GLEAM_ROUND_DOWN_BOX) YNEG->color((Fl_Color)221) YNEG->labelcolor((Fl_Color)55) YNEG->callback((Fl_Callback*)YNEG_CB)
ZNEG = new Fl_Button(193, 375, 45, 50, "Z-") ZNEG->tooltip("Moves the cutter up") ZNEG->box(FL_GLEAM_ROUND_DOWN_BOX) ZNEG->color((Fl_Color)198) ZNEG->callback((Fl_Callback*)ZNEG_CB) ZPOS = new Fl_Button(193, 435, 45, 50, "Z") ZPOS->tooltip("Moves the cutter down") ZPOS->box(FL_GLEAM_ROUND_DOWN_BOX) ZPOS->color((Fl_Color)198) ZPOS->callback((Fl_Callback*)ZPOS_CB) BOX1 = new Fl_Box(10, 326, 245, 177) BOX1->box(FL_GLEAM_DOWN_FRAME) BOX1->color((Fl_Color)33) BOX1->labelsize(24) COMMANDLINE = new Fl_Input(10, 251, 245, 47, "Command Line") COMMANDLINE->tooltip("Excepts gcode and grbl commands") COMMANDLINE->box(FL_GLEAM_ROUND_DOWN_BOX) COMMANDLINE->callback((Fl_Callback*)COMMANDLINE_CB) COMMANDLINE->align(Fl_Align(FL_ALIGN_TOP_LEFT)) PORT = new Fl_Input(59, 49, 158, 30, "Port: ") PORT->tooltip("The full path of the serial device /dev/ttyUSB0") PORT->box(FL_GLEAM_ROUND_DOWN_BOX) PORT->callback((Fl_Callback*)PORT_CB) PORT->value("/dev/ttyUSB0") BAUDRATE = new Fl_Input(58, 94, 160, 30, "Baud:") BAUDRATE->tooltip("grbl needs 115200 but you can use 2400,4800,9600,19200,38400,57600") BAUDRATE->box(FL_GLEAM_ROUND_DOWN_BOX) BAUDRATE->callback((Fl_Callback*)BAUD_CB) BAUDRATE->value("115200") CONNECT = new Fl_Light_Button(58, 139, 160, 47, "Connect") CONNECT->tooltip("Opens port or closes port the led displays status") CONNECT->box(FL_GLEAM_ROUND_DOWN_BOX) CONNECT->color((Fl_Color)197) CONNECT->callback((Fl_Callback*)CONNECT_CB) BOX2 = new Fl_Box(10, 32, 245, 171, "Serial") BOX2->box(FL_GLEAM_DOWN_FRAME) BOX2->color(FL_FOREGROUND_COLOR) BOX2->selection_color((Fl_Color)43) BOX2->labelsize(24) BOX2->align(Fl_Align(FL_ALIGN_TOP_LEFT))
OUTPUT = new Fl_File_Browser(265, 32, 175, 471) OUTPUT->box(FL_GLEAM_ROUND_DOWN_BOX)
WINDOW->end() WINDOW->show(argc, argv) Fl::run()
|
|
|
Post by rikky on Feb 2, 2019 9:31:15 GMT 1
Well I do not see the syntax error, but I''l look at it later. In the mean time I sniffed a bit in the manuals, and putted the IMODES OMODES etc nearly all togetther. Only the ~CRTSCTS I can not find. Not that I've got it to work unfortunatly, but maybe later; ' Open the serial port OPEN usb_port$ FOR DEVICE AS myserial
' Set speed - B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400 SETSERIAL myserial SPEED B115200 SETSERIAL myserial CMODE CS8 SETSERIAL myserial IMODE ~IGNBRK SETSERIAL myserial IMODE ~BRKINT SETSERIAL myserial IMODE ~ICRNL '~imaxbel //windows SETSERIAL myserial OMODE ~OPOST SETSERIAL myserial OMODE ~ONLCR SETSERIAL myserial LMODE ~ISIG SETSERIAL myserial LMODE ~ICANON SETSERIAL myserial LMODE ~IEXTEN SETSERIAL myserial LMODE ~ECHO SETSERIAL myserial LMODE ~ECHOE SETSERIAL myserial LMODE ~ECHOK SETSERIAL myserial LMODE ~ECHOCTL SETSERIAL myserial LMODE ~ECHOKE : ' only bsd SETSERIAL myserial LMODE NOFLSH SETSERIAL myserial IMODE ~IXON
'I suppose CMODE or OTHER SETSERIAL myserial OTHER ~CRTSCTS
Rik.
|
|
|
Post by rikky on Feb 2, 2019 18:28:59 GMT 1
Your GUI now works though, I can cummunicate with my scetch. Okee, I'll figure it out. Thanks Rik.
|
|
|
Post by bigbass on Feb 2, 2019 19:56:58 GMT 1
Hello Rik
thanks for the feedback that the GUI works for you too
about the syntax error with SYSTEM following what you were trying to do it would look like this
if you notice in my above code read first then wrote to get it to work without cat
HTH
Joe
usb_port$ = "/dev/ttyACM0" baudrate$ = "115200" SETENVIRON "PORTTEXT",usb_port$ SETENVIRON "BUADRATETEXT", baudratetext$
SYSTEM(" stty -F \"$PORTTEXT\" cs8 \"$BAUDRATETEXT\" ignbrk \ -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo \ -echoe -echok -echoctl -echoke noflsh -ixon -crtscts") PRINT porttext$ , baudratetext$ 'something INPUT goes here possibly HUG OPEN porttext$ FOR READWRITE AS arduino WRITELN sendtext$ TO arduino IF LEN(sendtext$) > 0 THEN PRINT sendtext$ SLEEP 50 END IF
|
|