|
Post by bigbass on Jan 4, 2019 19:53:48 GMT 1
This is is a GUI that will connect to the Raspberry pi3 GPIO pins I coded it all in fltk and bacon must be root to write to the pins The first check box registers the pin to be seen in linux the second adjacent check box sends a 0 or a 1 to the pin when done uncheck the boxes to clean up the memory If you do any hardware hacking this will make it easier the header of the code explains how it is to be used Joe dont forget to look at the official reference to the pins pinout.xyz/pipin.bac.tar.gz (4.87 KB)
|
|
|
Post by Pjot on Jan 5, 2019 10:05:49 GMT 1
Hi Joe, That looks really good! Well done Best regards Peter
|
|
|
Post by rikky on Jan 6, 2019 9:16:40 GMT 1
I was thinking of using wiringpi to control the pins. I believe Alexfish had some example using this library. but now I see you can simply do something like: to set a pin HIGH or: SAVE STR$(pinnumber) TO "/sys/class/gpio/unexport" to set a pin LOW With 3.3 Volts if I am correct. Thanks for that. Which leads me to something I have now seen a lot, but did not understand. I still do not understand, but you cannot ask all the questions you have at once, for there are simply too many sometimes. What is this PRINT "LABEL: ",dummy->label() FORMAT "%s%s\n" PRINT "VALUE: ",dummy->value() FORMAT "%s%d\n"
Where do the label() or value( ) come from. I do not see them defined somewhere. What is this '->' mean? It's not BaCon language I suppose. Thanks Rik.
|
|
|
Post by Pjot on Jan 6, 2019 20:48:24 GMT 1
Hi Rik, Your questions relate to C++ syntax. In the code from Joe, you'll see that 'dummy' is an instantiated object of the FL_Button class, which contains methods like 'label()' and 'value()'. These methods cannot be found within BaCon, but they are mentioned in the documentation of the used library (e.g. FLTK). Some methods are inherited from an object higher in the object hierarchy. For example, the 'label()' method is defined in the FL_Widget class, of which the FL_Button is a child. So FL_Button inherits the 'label()' method from its parent. Anyway, if this seems hocus pocus to you, just leave it. It is a C++ way of thinking You may be interested to know that the code generated by BaCon can be compiled both by a C compiler and also by a C++ compiler. The reason for this is that we want to have access to libraries which are created in C++, like the FLTK library. HTH Peter
|
|
|
Post by bigbass on Jan 7, 2019 4:59:56 GMT 1
First I want to give a double thanks to Peter for your comments and your detailed explanation you gave to Rik because I was really busy over the weekend thanks (it was very clear and to the point) Rik I will use a gtk/gdk example instead of fltk for the moment since I saw that you used gtk imports before in another post and I think that this will address your question about syntax another way we are able to get C structures three ways in BaCon ( when and if we need to use low level events) ====================================================== 1.) HARDWARE_CODE = (event->hardware_keycode) PRINT "event hardware_keycode as a variable ", HARDWARE_CODE 2.)PRINT "event hardware_keycode directly using print ",(event->hardware_keycode) 3.)PRINT " this syntax says the same thing ", event[0].hardware_keycode ======================================================================= referece link developer.gnome.org/gdk3/stable/gdk3-Event-Structures.html#GdkEventKeyand some more bacon code basic-converter.proboards.com/thread/493/structures-classes?page=1a struct is used in C we can port it to a RECORD for BaCon or we can be lazy an enclose it in USEC ENDUSEC ------------------------------------------------- C++ a struct in C is a public class in C++ but in C++ we can also have functions in the class and we have the "new" command to store in memory generally speaking I spent a lot of time sorting out how to get C++ classes to play nicely with events and getting it to compile cleanly in Bacon and its still a work in progress... I had posted some discoveries I made along the way for gtk/gdk and also for fltk in several threads Peter wrote bacongui-fltk.bac and I am sure he spent his fair share of time sorting out everything IN Pure C++ /** Buttons test callback */ static void button_cb(Fl_Button *b, void *) { char msg[256]; sprintf(msg, "Label: '%s'\nValue: %d", b->label(),b->value()); printf("%s\n",msg); }
'--- doing it in pure C++ is not evil but lets give bacon some work to do '--- if you want to port it DECLARE msg[256] TYPE char sprintf(msg, "Label: '%s'\nValue: %d", dummy->label(),dummy->value()) printf("%s\n",msg) '--- lets use bacon to PRINT cheating a little to reduce the code PRINT "LABEL: ",dummy->label() FORMAT "%s%s\n" PRINT "VALUE: ",dummy->value() FORMAT "%s%d\n" I have a lot of questions too and the forum users vovchik ,Alex and Peter have always been very helpful Joe
|
|
|
Post by rikky on Jan 7, 2019 10:46:26 GMT 1
Thanks, this is a very thorough explanation. It' still hocus pocus indeed, but I realy want to get some grip on this mater, so .. I will have to digest on this for a while... Thanks Rik.
|
|
|
Post by bigbass on Jan 9, 2019 17:41:01 GMT 1
Well the Raspberry pi3 GUI to send to the gpio pins is working well to send logic now the next step is to connect it to a micro controller I am testing with an arduino nano a beautifully tiny breadboard friendly version the image is the actual size the first program I uploaded /burned to the nano was Grbl (I used the arduino ide and used the grbl source code from github) An open source, embedded, high performance g-code-parser and CNC milling controller written in optimized C that will run on a straight Arduino Grbl is a no-compromise, high performance, low cost alternative to parallel-port-based motion control for CNC milling. It will run on a vanilla Arduino (Duemillanove/Uno) as long as it sports an Atmega 328. 1.) so now the nano board has this Grbl code dedicated to convert gcode to motion xyz using stepper motors you can connect to the nano and test cnc software without connecting to the stepper motors the software will run as if it was really making the part 2.) I am using bcnc software to test if the grbl on the nano is working a note when using the nano you have to change the port to /dev/ttyUSB0 to get it to work now I know that it will run the motors ! using the raspberry pi3 and an arduino nano micro controller I will later make a GUI for the arduino nano board and line up the pins so that it will be easy connect to from the rasberry pi The goal in the end is I don't want to do testing in python I prefer to port the demos to bacon Joe
|
|
|
Post by vovchik on Jan 10, 2019 15:20:57 GMT 1
Dear Joe,
Great stuff. I don't have an arduino for testing but I can imagine that you can do very interesting things. I have always thought that gutting/modding a disused inkjet printer, replacing the cartridges with burning lasers, would be a nice idea - a kind of precision homemade cutting tool.
With kind regards, vovchik
|
|
|
Post by rikky on Jan 10, 2019 15:26:19 GMT 1
Some sort of GUI to program/communicate with an Arduino ? In BaCon? That would be realy welcome, I suppose. Imagine, you can just 'talk' to your wheelchair and say; "Climb the steps". And the 'thing' goes climbing the steps. (in BaCon) First proposal would be some INCLUDE with things like DIGITALREAD and DIGITALWRITE(pinnumber,value) Rik.
|
|
|
Post by rikky on Jan 10, 2019 17:50:23 GMT 1
To be honest, I have already played a bit with Arduino before. The most basic Linux way to 'talk' to the Arduino was with the serial console with a command as easy to remember as: stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
After then SEND is : echo "something" > /dev/ttyACM0 And RECEIVE is : Now you can throw away the IDE or Python for serial communication. I believe programming, or uploading a scetch can be done the same way. I hope this is of some help. Rik.
|
|
|
Post by bigbass on Jan 10, 2019 18:56:54 GMT 1
Hey Guys Here is a better way to explain with an image I actually coded it already! lined up the pins and from the pi we can simulate the arduino nanos pinouts (but no so fast yet we need a buffered logic level shifter because the pi uses 3,3 v logic and the arduino uses 5 volt logic ) I will build that today before I connect but thats a hardware thing no problem but we can with the buffered logic shifter write code in bacon and control anything directly and it becomes part of the linux file system I will upload the GUI after testing with real hardware Joe
|
|
|
Post by bigbass on Jan 12, 2019 8:54:27 GMT 1
How to connect to the arduino nano using a serial connection from the raspberry pi3 using a USB to usb mini cable
I probably skipped a lot of official steps because I started out with a non arduino sketch and went straight to a gcode converter (hex code) loaded into it arduino nano this will allow me to connect to any quality cnc software for linux and convert any image to gcode first then the machining of the part is done by translating the the gcode with grbl to real world motion xyz from the stepper motors
but the serial connection idea doesn't change I wanted to see if I could go command line and manually send code to the micro controller
and stumbled around for a bit because you have to set everything up exactly or it wont work and for me the default 9600 baud rate was what caused my problems
The easy way was install putty that will make for an easier first time connection with a gui
1.)type putty from the terminal
2.) when inside the putty gui go to the bottom left hand column and select serial
3.) change the default /dev/ttyS0 to /dev/ttyUSB0
4.) change the default baud rate from 9600 to 115200 (or it wont work at all)
5.) click the button Open
6.) look a the left hand column again and select session its the first choice
7.) look to the right for a radio button serial check it
8.) if all went well in putty it should display in the gui serial line is /dev/ttyUSB0 speed 115200
9.) press the button Open and you should be in a putty terminal
10,) in my case it says Grbl 1.1g ['$' for help] this means I am connected to the micro controller now!
I can manually send code to the micro controller without any other help from python or arduino ide enough for today ...
tomorrow I will try to do that serial connection in pure bacon code (and go around putty)
Joe
|
|
|
Post by rikky on Jan 13, 2019 8:05:18 GMT 1
That would be something like : Got something like this to work several years ago. stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts I do not have a NANO, but I have a UNO for testing. Should not be too different. I hope I'll get some time for this today. Rik.
|
|
|
Post by rikky on Jan 13, 2019 14:40:37 GMT 1
Pfff, Normal serial communication indeed it works with a scetch like: char receivedChar; boolean newData = false;
void setup() { Serial.begin(9600); Serial.println("<Arduino is ready>"); }
void loop() { recvOneChar(); showNewData(); }
void recvOneChar() { if (Serial.available() > 0) { receivedChar = Serial.read(); newData = true; } }
void showNewData() { if (newData == true) { //Serial.print("This just in ... "); Serial.print(receivedChar); newData = false; } } You have to NOT open the serial console of your IDE And open two terminals on your Pi. On both you have to stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts This can probbably be shortened. And then on one tail -f /dev/ttyACM0
And then with the other you can echo whatever you like to the /dev/ttyACM0 You'll see it appear on your first terminal. In BaCon : ehhh OPEN "/dev/ttyACM0" FOR DEVICE AS myserial SETSERIAL myserial SPEED B9600 SETSERIAL myserial IMODE ~IGNBRK ... ehh Pff?? Programming is even a lot more difficult. You need at least gcc-avr avr-libc avrdude. Rik.
|
|
|
Post by bigbass on Jan 14, 2019 19:07:44 GMT 1
hello Rik yes Pffff! a lot of work thanks for your perspective I will use the command line option after I have the code confirmed to communicate correctly with the nano Hello guys I wanted to go about this using official libraries www.intra2net.com/en/developer/libftdi/documentation/I ported that to bacon of course I compiled it in c and c++ first to verify the results are the same and are correct you may need more but at least this dependency sudo apt-get install libftdipp1-dev libftdi-dev - Development files for libftdi libftdi1 - Library to control and program the FTDI USB controller libftdi1-2 - Library to control and program the FTDI USB controllers there is a post going back to 2011 I went about it a different way and have the hardware to this test on basic-converter.proboards.com/thread/95/ftdi-support-puppy-linuxthere is a lot of good info in that post but however chipid was not working correctly and it was easier for me to port the source code demo and get the chipid working '--- ported the official simple.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 TYPE int DECLARE ftdi TYPE struct ftdi_context* DECLARE version TYPE struct ftdi_version_info 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 ftdi_free(ftdi)
call it simple6.bac and compile it sudo ./simple6 Initialized libftdi 1.3 FTDI chipid: 81A8C35D Joe
|
|