|
Post by alexfish on Dec 30, 2023 22:55:43 GMT 1
TB6600 Findings Update
Raspberry pi4 VOH Output high voltageb VDD IO = 3.3V, IOH = 2mA TBD - - V
TB6600 logic current mA
lowest average max 8 10 15
StepperMotor Typical Nema17 - Neam24
For The ME:Advice Sitting Here : logic level shifter in both cases are best logic
This way All Ends Are Covered
Want A cover all device :: search RPi 3.3V to 5V 26 I/O Bidirectional Voltage-Level Shifter Module for Raspberry Pi + A pico version is available
bit by bit logic level shifter is cheapest,or is it
BR Alex
|
|
|
Post by alexfish on Dec 31, 2023 1:16:56 GMT 1
Q: Are there any other Pro Solutions other than LinuxCNC A:Yes Q: All See Screen Shot on Raspberry PI 4 Download and install tip look for '/installing-planetcnc-tng-rpi3' if install.and desktop/link fails use the terminal in the planetcnc directory IE pi@raspberrypi:~ $ cd /home/pi/PlanetCNC pi@raspberrypi:~/PlanetCNC $ sudo sh install.sh cp: cannot create regular file '/root/Desktop/': Not a directory chmod: cannot access '/root/Desktop/PlanetCNC.desktop': No such file or directory pi@raspberrypi:~/PlanetCNC $ ./PlanetCNCRPi.exe and Yes I have just installed it and not tested But it sees the gcode produced by HUG GCODE file formats Are Gcode NC drill DFX PLT etc SVG CSV + IMPORT image screenshot also shows the exported ARC/Quadrant Desktop Fix copy this code and save as destop.sh in the PlanetCNC directory & set permissions #!/bin/bash
FILE=PlanetCNC.desktop printf '[Desktop Entry]\n' >>$FILE printf 'Name=PlanetCNC\n' >>$FILE printf 'Comment=PlanetCNC Software\n' >>$FILE printf 'Exec=' >>$FILE printf $PWD >>$FILE printf '/PlanetCNCRPi.exe\n' >>$FILE printf 'Icon=' >>$FILE printf $PWD >>$FILE printf '/PlanetCNC_Icon.svg\n' >>$FILE printf 'Path=' >>$FILE printf $PWD >>$FILE printf '\n' >>$FILE printf 'Type=Application\n' >>$FILE printf 'Terminal=false\n' >>$FILE printf 'StartupNotify=true\n' >>$FILE printf 'Categories=PlanetCNC;Engineering;Robotics;\n' >>$FILE printf 'Keywords=CNC;\n' >>$FILE cp $FILE ~/Desktop/ chmod +x ~/Desktop/PlanetCNC.desktop chmod +x PlanetCNCRPi.exe
From the terminal pi@raspberrypi:~ $ cd /home/pi/PlanetCNC pi@raspberrypi:~/PlanetCNC $ ./desktop.sh BR Alex Attachments:
|
|
|
Post by alexfish on Jan 6, 2024 21:40:31 GMT 1
So Here we are not Breaking the Rule HA
+ The DO NOT DO esp on Raspi PLEASE READ
Here taking Peters CANVAS FUNCTION that will do Ellipses & Circles Apply The GCODE RULE 1 :: here taking 0.001 :
Will seen All in the EDIT :: = Start & End Bang On the Nail The Draw function = Replicating the Steps
Have Fun + BR Alex
Will Update code :: S law got a bug in final version::
OPTION PARSE FALSE
USEH #define PRINTS(arg1,arg2,arg3) sprintf(arg3,arg2,arg1) END USEH
PROTO PRINTS
FUNCTION MYEVAL$(double hug_number,int decimal_places) TYPE STRING
LOCAL EVS$ IF decimal_places > -1 THEN
EVS$ ="%." & STR$(decimal_places) & "f" LOCAL gx[20] TYPE static char
PRINTS(hug_number,EVS$,gx)
RETURN gx
ELSE RETURN NULL END IF
END FUNCTION
INCLUDE "hug.bac" HUGOPTIONS("NOSCALING")
SUB OX02(double x, double y, double xsize, double ysize,double step) LOCAL ptr LOCAL i, xt, yt TYPE double LOCAL xt$,yt$ SQUARE("#000000",0,0,1000,700,1) SYNC
'Try not to use For Loops in these types of apps 'use while with Bacon Sleep(10) to free resources for other apps ' Calcs First Then the doing i=0 WHILE i <= 360 DO SYNC xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) TEXT(ed,STR$(ptr)) TEXT(ed," G01 X " & xt$) TEXT(ed," Y " & yt$ & NL$) INCR ptr INCR i,step SLEEP 10 WEND SYNC SLEEP 1000 i=0 WHILE i <= 360 DO SYNC xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) PIXEL("#FF0000",VAL(xt$),VAL(yt$)) INCR i,step SLEEP 10 WEND END SUB
win = WINDOW("gcode",1200,750) can = CANVAS(950,700) ATTACH(win,can,0,50) ed = EDIT(250,700) ATTACH(win,ed,950,50) OX02(0,0,150,200,0.01)
DISPLAY
No A bug :: have got this Browser Hogging The resourses
|
|
|
Post by alexfish on Jan 6, 2024 22:44:39 GMT 1
Argh Ended up with This The raw code was working but in gtk 2 things a going *UP Here We Go OPTION PARSE FALSE
USEH #define PRINTS(arg1,arg2,arg3) sprintf(arg3,arg2,arg1) END USEH
PROTO PRINTS
FUNCTION MYEVAL$(double hug_number,int decimal_places) TYPE STRING
LOCAL EVS$ IF decimal_places > -1 THEN
EVS$ ="%." & STR$(decimal_places) & "f" LOCAL gx[20] TYPE static char
PRINTS(hug_number,EVS$,gx)
RETURN gx
ELSE RETURN NULL END IF
END FUNCTION
INCLUDE "hug.bac" HUGOPTIONS("NOSCALING")
SUB OX02(double x, double y, double xsize, double ysize,double step) LOCAL Gcode$ LOCAL ptr LOCAL i, xt, yt TYPE double LOCAL xt$,yt$
'Try not to use For Loops in these types of apps 'use while with Bacon Sleep(10) to free resources for other apps ' Calcs First Then the doing i=0 WHILE i <= 360 DO xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) Gcode$ = Gcode$ & STR$(ptr) Gcode$ = Gcode$ & " G01 X " & xt$ Gcode$ = Gcode$ & " Y " & yt$ & NL$ INCR ptr INCR i,step WEND TEXT(ed,Gcode$) SQUARE("#000000",0,0,1000,700,1) SYNC SLEEP 1000 i=0 WHILE i <= 360 DO SYNC xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) PIXEL("#FF0000",VAL(xt$),VAL(yt$)) INCR i,step SLEEP 10 WEND END SUB
win = WINDOW("gcode",1200,750) can = CANVAS(950,700) ATTACH(win,can,0,50) ed = EDIT(250,700) ATTACH(win,ed,950,50) OX02(0,0,150,200,0.01)
DISPLAY Put The Kettle On and a a Cuppa Yet in the final draw will be able to break from the App Need to look further But Here can get a straight Drop, yet safe in the knowledge the gpio will work with the above OPTION PARSE FALSE
USEH #define PRINTS(arg1,arg2,arg3) sprintf(arg3,arg2,arg1) END USEH
PROTO PRINTS
FUNCTION MYEVAL$(double hug_number,int decimal_places) TYPE STRING
LOCAL EVS$ IF decimal_places > -1 THEN
EVS$ ="%." & STR$(decimal_places) & "f" LOCAL gx[20] TYPE static char
PRINTS(hug_number,EVS$,gx)
RETURN gx
ELSE RETURN NULL END IF
END FUNCTION
INCLUDE "hug.bac" HUGOPTIONS("NOSCALING")
SUB OX02(double x, double y, double xsize, double ysize,double step) LOCAL Gcode$ LOCAL ptr LOCAL i, xt, yt TYPE double LOCAL xt$,yt$
'Try not to use For Loops in these types of apps 'use while with Bacon Sleep(10) to free resources for other apps ' Calcs First Then the doing i=0 WHILE i <= 360 DO xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) Gcode$ = Gcode$ & STR$(ptr) Gcode$ = Gcode$ & " G01 X " & xt$ Gcode$ = Gcode$ & " Y " & yt$ & NL$ INCR ptr INCR i,step WEND TEXT(ed,Gcode$) SQUARE("#000000",0,0,1000,700,1) SYNC SLEEP 1000 i=0 WHILE i <= 360 DO xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) PIXEL("#FF0000",VAL(xt$),VAL(yt$)) INCR i,step WEND END SUB
win = WINDOW("gcode",1200,750) can = CANVAS(950,700) ATTACH(win,can,0,50) ed = EDIT(250,700) ATTACH(win,ed,950,50) OX02(0,0,150,200,0.01)
DISPLAY Added For other viewers hitting on the nail with SIN & COS can be a teaser esp at end of a run Tail end results here "line num" "Xpos" "Ypos" 35994 G01 X 300.00 Y 199.79 35995 G01 X 300.00 Y 199.83 35996 G01 X 300.00 Y 199.86 35997 G01 X 300.00 Y 199.90 35998 G01 X 300.00 Y 199.93 35999 G01 X 300.00 Y 199.97 36000 G01 X 300.00 Y 200.00 BR Alex Added Timing Draw HUG353 & HUG Theoretical Traverse and cutting rates Added Picky Attachments:
|
|
|
Post by alexfish on Jan 6, 2024 23:24:49 GMT 1
Normally I do not like flying off Piste :: or if had good time drop the e But Here We go The Driver a4988 :: Shield Ordered these 2 off, they are meant for the UNO but can work well with Raspberry Pi the Vref for the driver "logic" = 3.5 To 5 volt and has various methods of connection the axis :: Please read the manual + tips of any sites that you visit Tech Wise why did I order 2 :: on small diy cnc's all axis are Twin lead Screw to stop Racking :: OK I paid at today's price £7.69 uk for the Pair if read the specs only need the The Raspi 3.5 volt for the logic ref : board has a two pin header to enable the enable leaving 2 pins dir + Step , from the pi for each axis + the 3.5v + ground , very minimalist BR Alex Q:: how does one connect two divers with one signal A:: read the docs :: there are TOP PINS and the under PINS to the UNO are linked :: Hence TWO BOARDS And Yes You Need the one that has XYZ& A that pairs :: in the main they are spare yet can access from the top terminal, so not real spare but the connectors are better suited for Likes of 24volt supplies (Screw terminal) + = a OCTOBPOARD Representation of MY Gadget( just installed SolveSpace ) Q: Is it Rigid A: Yes Q: is Light Weight A: Yes Q: What do you call it A: CNCIAB :: CNC IN A BOX (lite wait & rigid Think "Cell Aluminium Honeycomb" for the core) Hints the two Y axis are detached from and place along and next to the x axis place the base to face of box:: fasten it to the box:: away you go Router in a box and sit it on top of whatever :: set up time . a quick as you can carry out the Mentioned Q: how long in the Designing A: Well Errrrrrr: if I payed my self I would be broke:: So here we go 9 months Q: what is the working area A: 550x650 ; X 650 wise, larger board can be fed through/ between the y two axis Q: Did you use cad A: No dimension wise and math wise and strength(engineering: moments of blah blagh ect) very challenging Q: is it cheap to make A: My name is Alex Picky Attachments:
|
|
|
Post by alexfish on Jan 7, 2024 4:13:53 GMT 1
Removal of line numbers and a direct export of Gcode The import of code in PlanetCNC No Adjustments only zoomed to Picky Attachments:
|
|
|
Post by alexfish on Jan 7, 2024 5:19:50 GMT 1
and the final clockwise & anti clockwise OPTION PARSE FALSE
USEH #define PRINTS(arg1,arg2,arg3) sprintf(arg3,arg2,arg1) END USEH
PROTO PRINTS
FUNCTION MYEVAL$(double hug_number,int decimal_places) TYPE STRING
LOCAL EVS$ IF decimal_places > -1 THEN
EVS$ ="%." & STR$(decimal_places) & "f" LOCAL gx[20] TYPE static char
PRINTS(hug_number,EVS$,gx)
RETURN gx
ELSE RETURN NULL END IF
END FUNCTION
INCLUDE "hug.bac" HUGOPTIONS("NOSCALING")
SUB OX02(double x, double y, double xsize, double ysize,double step) LOCAL Gcode$ LOCAL ptr LOCAL i, xt, yt TYPE double LOCAL xt$,yt$ SQUARE("#000000",0,0,950,700,1) SYNC 'Try not to use For Loops in these types of apps 'use while with Bacon Sleep(10) to free resources for other apps ' Calcs First Then the doing i=0 WHILE i <= 360 DO xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) Gcode$ = Gcode$ & "G01 X " & xt$ Gcode$ = Gcode$ & " Y " & yt$ & NL$ INCR ptr INCR i,step WEND TEXT(ed,Gcode$) SYNC SLEEP 1000 i=0 WHILE i <= 360 DO SYNC xt = xsize*COS(RAD(i))+xsize yt = ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) PIXEL("#FF0000",VAL(xt$),VAL(yt$)) INCR i,step SLEEP 5 WEND END SUB
SUB OX03(double x, double y, double xsize, double ysize,double step) LOCAL Gcode$ LOCAL ptr LOCAL i, xt, yt TYPE double LOCAL xt$,yt$
SQUARE("#000000",0,0,950,700,1) SYNC 'Try not to use For Loops in these types of apps 'use while with Bacon Sleep(10) to free resources for other apps ' Calcs First Then the doing i=360 WHILE i >= 0 DO xt = -xsize*COS(RAD(i))+xsize yt = -ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) Gcode$ = Gcode$ & "G01 X " & xt$ Gcode$ = Gcode$ & " Y " & yt$ & NL$ INCR ptr DECR i,step WEND TEXT(ed,Gcode$) SYNC SLEEP 1000 i=360 WHILE i >= 0 DO SYNC xt = -xsize*COS(RAD(i))+xsize yt = -ysize*SIN(RAD(i))+ysize xt$ = MYEVAL$(xt+x,2) yt$ = MYEVAL$(yt+y,2) PIXEL("#FF0000",VAL(xt$),VAL(yt$)) DECR i,step SLEEP 5 WEND END SUB SUB Draw() OX03(0,0,150,200,0.02) END SUB win = WINDOW("gcode",1200,750) but = BUTTON("Draw",100,35) ATTACH(win,but,6,6) CALLBACK(but,Draw) can = CANVAS(950,700) ATTACH(win,can,0,50) ed = EDIT(250,700) FONT(ed,"monospace 12px") ATTACH(win,ed,950,50)
DISPLAY + a youtube video that will explain dual leadscrew : THE WHY although this demos the Z axis principal + it be a 3d printer the ME = APPLY to all Axis if searching recent changes happening in such devices then will find more and more and are adopting their own method to the doing, + read the why , some say = closed source, that is not true esp if understand what is going on and the math behind it. hence , here can see the results translated to gcode The YouTube Link www.youtube.com/watch?v=6UgT9YqY3UAADDED Have posted some Q A's + general arrangement at post where head = BR Alex
|
|
|
Post by alexfish on Jan 7, 2024 17:59:58 GMT 1
Still on the focus OF Raspberry PI Raspberry PI & the PI PICO And What is the difference Food For Thought Pico SDK Blink example and Wiring PI Blink Example #include <stdio.h> #include <wiringPi.h>
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
#define LED 0
int main (void) { printf ("Raspberry Pi blink\n") ;
wiringPiSetup () ; pinMode (LED, OUTPUT) ;
for (;;)
{ digitalWrite (LED, HIGH) ; // On delay (500) ; // mS digitalWrite (LED, LOW) ; // Off delay (500) ; } return 0 ; } /** * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause */
#include "pico/stdlib.h"
int main() { #ifndef PICO_DEFAULT_LED_PIN #warning blink example requires a board with a regular LED #else const uint LED_PIN = PICO_DEFAULT_LED_PIN; gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); while (true) { gpio_put(LED_PIN, 1); sleep_ms(250); gpio_put(LED_PIN, 0); sleep_ms(250); } #endif
Wiring Pi Speed test /* * speed.c: * Simple program to measure the speed of the various GPIO * access mechanisms. * * Copyright (c) 2012-2013 Gordon Henderson. *********************************************************************** * This file is part of wiringPi: * https://github.com/WiringPi/WiringPi * * wiringPi is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * wiringPi is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with wiringPi. If not, see <http://www.gnu.org/licenses/>. *********************************************************************** */
#include <wiringPi.h>
#include <stdio.h> #include <stdlib.h> #include <stdint.h>
#define FAST_COUNT 10000000 #define SLOW_COUNT 1000000 #define PASSES 5
void speedTest (int pin, int maxCount) { int count, sum, perSec, i ; unsigned int start, end ;
sum = 0 ;
for (i = 0 ; i < PASSES ; ++i) { start = millis () ; for (count = 0 ; count < maxCount ; ++count) digitalWrite (pin, 1) ; end = millis () ; printf (" %6d", end - start) ; fflush (stdout) ; sum += (end - start) ; }
digitalWrite (pin, 0) ; printf (". Av: %6dmS", sum / PASSES) ; perSec = (int)(double)maxCount / (double)((double)sum / (double)PASSES) * 1000.0 ; printf (": %7d/sec\n", perSec) ; }
int main (void) { printf ("Raspberry Pi wiringPi GPIO speed test program\n") ; printf ("=============================================\n") ;
// Start the standard way
printf ("\nNative wiringPi method: (%8d iterations)\n", FAST_COUNT) ; wiringPiSetup () ; pinMode (0, OUTPUT) ; speedTest (0, FAST_COUNT) ;
// GPIO
printf ("\nNative GPIO method: (%8d iterations)\n", FAST_COUNT) ; wiringPiSetupGpio () ; pinMode (17, OUTPUT) ; speedTest (17, FAST_COUNT) ;
// Phys
printf ("\nPhysical pin GPIO method: (%8d iterations)\n", FAST_COUNT) ; wiringPiSetupPhys () ; pinMode (11, OUTPUT) ; speedTest (11, FAST_COUNT) ;
// Switch to SYS mode:
system ("/usr/local/bin/gpio export 17 out") ; printf ("\n/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ; wiringPiSetupSys () ; speedTest (17, SLOW_COUNT) ;
return 0 ; }
Raspberry PI4 results pi@raspberrypi:~/Downloads/WiringPi-master/examples $ ./speed Raspberry Pi wiringPi GPIO speed test program =============================================
Native wiringPi method: (10000000 iterations) 209 154 155 153 154. Av: 165mS: 60606060/sec
Native GPIO method: (10000000 iterations) 165 161 162 160 161. Av: 161mS: 61804697/sec
Physical pin GPIO method: (10000000 iterations) 163 163 161 162 161. Av: 162mS: 61728395/sec
/sys/class/gpio method: ( 1000000 iterations) 17 17 16 16 16. Av: 16mS: 60975609/sec
BR Alex ADDED a Did You Know Did Know Raspi wiring gpio is buffered using FIFO(size) + can test "is empty":: hence If Mask the outputs as mention Then any varying of the speed is not important :: ie if XYZ gets triggered at the Same Time and looking at raspi PI4 speed test ,not really Consequential Further To :: still read through the Wiring pi bits I to chuckle at this #ifdef DONT_CARE_ANYMORE if (! (strstr (line, "BCM2708") || strstr (line, "BCM2709") || strstr (line, "BCM2835"))) { fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ; fprintf (stderr, " - expecting BCM2708, BCM2709 or BCM2835.\n") ; fprintf (stderr, "If this is a genuine Raspberry Pi then please report this\n") ; fprintf (stderr, "at GitHub.com/wiringPi/wiringPi. If this is not a Raspberry Pi then you\n") ; fprintf (stderr, "are on your own as wiringPi is designed to support the\n") ; fprintf (stderr, "Raspberry Pi ONLY.\n") ; exit (EXIT_FAILURE) ; } #endif
// Actually... That has caused me more than 10,000 emails so-far. Mosty by // people who think they know better by creating a statically linked // version that will not run with a new 4.9 kernel. I utterly hate and // despise those people. // // I also get bleats from people running other than Raspbian with another // distros compiled kernel rather than a foundation compiled kernel, so // this might actually help them. It might not - I only have the capacity // to support Raspbian. // // However, I've decided to leave this check out and rely purely on the // Revision: line for now. It will not work on a non-pi hardware or weird // kernels that don't give you a suitable revision line.
// So - we're Probably on a Raspberry Pi. Check the revision field for the real // hardware type // In-future, I ought to use the device tree as there are now Pi entries in // /proc/device-tree/ ... // but I'll leave that for the next revision. Or the next.
// Isolate the Revision line Also have mentioned in the past about various distro's and methods posted on this forum My Normal response is as for other devices, best one tested to date was from Libre computer Le Potato pi If check the web site , the pio pins are listed + works well with their Raspbian Image they do the 1gb version (not suitable for streaming and the likes of) Price comparable to the old phrase £35 computer link for wiring tool wiring-toolEOF
|
|
|
Post by alexfish on Jan 8, 2024 23:28:56 GMT 1
Some final bits with reference to Raspberry PI and can the move on a pico is arriving soon so not tested : as mentioned pico sdk:: one can compile in C and so to PICOBASIC based on BaCon requires avr-gcc for those of interest an test a theory:: no further docs first a mine parser in BaCon in it is a call to samefile.c using gcc compile to see the results of the parsed file:: 'picobasic BaSic 1. test theory using avr-gcc /* from pico sdk You now have `hello_world.elf` to load via a debugger, or `hello_world.uf2` that can be installed and run on your Raspberry Pi Pico via drag and drop. the me says should be able to connect to the pico using raspbery pi os via wiring pi/ gpio serial rx & tx */ HOME$ = GETENVIRON$("HOME") CHANGEDIR HOME$ DECLARE head$ = "#include <string.h>" & NL$ & "#include <stdio.h>" & NL$ & "#include <stdlib.h>" & NL$ & "#include <stdarg.h>" & NL$ & "#include <math.h>" & NL$ head$ = head$ & "#define STRING char" & NL$ & "#define STRINGBUF 1024" & NL$
DECLARE main$ = "int main(int argc, char **argv) {" & NL$ & NL$ DECLARE end$ = NL$ & "return 0;" & NL$ & "}" & NL$
FUNCTION handle_for$(my_for$) LOCAL first_var$,last_var$ my_for$ = REPLACE$(my_for$, "STEP", ";") first_var$ = INBETWEEN$(my_for$,"FOR","=") last_var$= MID$(my_for$,INSTR(my_for$,";")+1)
IF INSTR(last_var$,"-") THEN
my_for$ = REPLACE$(my_for$,";",";" & first_var$ & "+=") my_for$ = REPLACE$(my_for$,"TO","; " & first_var$ & " >= ") my_for$ = REPLACE$(my_for$,"FOR","for(") my_for$ = my_for$ & ")"
ELSE my_for$ = REPLACE$(my_for$,";",";" & first_var$ & "+=") my_for$ = REPLACE$(my_for$,"TO","; " & first_var$ & " <= ") my_for$ = REPLACE$(my_for$,"FOR","for(") my_for$ = my_for$ & ")"
END IF
IF INSTR(my_for$,":") THEN my_for$ = REPLACE$(my_for$,":","")
ELSE my_for$ = REPLACE$(my_for$,":","")
END IF
my_for$ = REPLACE$(my_for$,":","") my_for$ = my_for$ & "{" & NL$ RETURN my_for$ RETURN my_for$
END FUNCTION
FUNCTION handle_while$(my_while$) TYPE STRING my_while$= REPLACE$(my_while$,"WHILE","while(" ) IF RIGHT$(my_while$,2) = "DO" THEN my_while$ = REPLACE$(my_while$,"DO","){") ELSE my_while$ = my_while$ & ")" END IF
RETURN my_while$ END FUNCTION
FUNCTION handle_sub$(my_sub$) TYPE STRING my_sub$ = REPLACE$(my_sub$,"SUB","void") my_sub$ = my_sub$ & "{" ' SUB test()*
my_sub$ = CHOP$(my_sub$) RETURN my_sub$ END FUNCTION
FUNCTION handle_function$(my_sub$) TYPE STRING LOCAL first_var$,last_var$ ' SUB test() TYPE char* last_var$ = MID$(my_sub$,INSTR(my_sub$,"TYPE")+4)
my_sub$ = REPLACE$(my_sub$,"FUNCTION",last_var$) my_sub$ = REPLACE$(my_sub$,"TYPE"," {") my_sub$ = MID$(my_sub$,1,INSTR(my_sub$,"{")+1) my_sub$ = CHOP$(my_sub$) RETURN my_sub$ END FUNCTION
SUB handle_file(STRING file$) LOCAL Bcode$ LOCAL Ccode$ = head$ LOCAL amount REM ============================================ OPEN file$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO
READLN txt$ FROM myfile txt$ = CHOP$(txt$)
IF LEFT$(txt$,7) = "INCLUDE" THEN txt$ = REPLACE$(txt$,"INCLUDE","#include") ELIF LEFT$(txt$,3) = "DEF" THEN txt$ = REPLACE$(txt$,"DEF","#define")
ELIF LEFT$(txt$,3) = "SUB" THEN txt$ = handle_sub$(txt$)
ELIF LEFT$(txt$,8) = "FUNCTION" THEN txt$ = handle_function$(txt$)
ELIF INSTR(txt$,"CALL") THEN txt$ = REPLACE$(txt$,"CALL"," ") txt$ = txt$ & ";"
ELIF LEFT$(txt$,2) = "IF" THEN txt$ = REPLACE$(txt$,"IF","if") txt$ = REPLACE$(txt$,"THEN","{")
ELIF LEFT$(txt$,5) = "ENDIF" THEN txt$ = REPLACE$(txt$,"ENDIF","}") ELIF LEFT$(txt$,6) = "END IF" THEN txt$ = REPLACE$(txt$,"END IF","}") ELIF LEFT$(txt$,6) = "RETURN" THEN txt$ = REPLACE$(txt$,"RETURN","return") txt$ = txt$ & ";" ELIF LEFT$(txt$,4) = "NEXT" THEN txt$ = REPLACE$(txt$,"NEXT" ,"}") ELIF LEFT$(txt$,4) = "WEND" THEN txt$ = REPLACE$(txt$,"WEND" ,"}") ELIF LEFT$(txt$,6) = "ENDSUB" THEN txt$ = REPLACE$(txt$,"ENDSUB" ,"}") ELIF LEFT$(txt$,7) = "END SUB" THEN txt$ = REPLACE$(txt$,"END SUB" ,"}") ELIF LEFT$(txt$,11) = "ENDFUNCTION" THEN txt$ = REPLACE$(txt$,"ENDFUNCTION" ,"}") ELIF LEFT$(txt$,12) = "END FUNCTION" THEN txt$ = REPLACE$(txt$,"END FUNCTION" ,"}")
ELIF LEFT$(txt$,5) = "PRINT" THEN txt$ = REPLACE$(txt$,"PRINT" ,"printf") txt$ = txt$ & ";" ELIF LEFT$(txt$,3) = "REM" THEN txt$ = REPLACE$(txt$,"REM" ,"//") txt$ = txt$ & ";" ELIF LEFT$(txt$,4) = "PUTS" THEN txt$ = REPLACE$(txt$,"PUTS" ,"puts") txt$ = txt$ & ";" ELIF LEFT$(txt$,4) = "COPY" THEN txt$ = REPLACE$(txt$,"COPY" ,"strcpy") txt$ = txt$ & ";" ELIF LEFT$(txt$,4) = "CONCAT$" THEN txt$ = REPLACE$(txt$,"CONCAT$" ,"strcat") txt$ = txt$ & ";" ELIF LEFT$(txt$,3) = "FOR" THEN txt$ = handle_for$(txt$) ELIF LEFT$(txt$,5) = "WHILE" THEN txt$ = handle_while$(txt$)
ELIF LEFT$(txt$,5) = "START" THEN txt$ = REPLACE$(txt$,"START","int main(int argc, char **argv) {" & NL$ & NL$) ELIF txt$ = "END" THEN txt$ = REPLACE$(txt$,"END",NL$ & "return 0;" & NL$ & "}" & NL$) ELIF LEFT$(txt$,5) = "LOCAL" THEN txt$ = REPLACE$(txt$,"LOCAL","") txt$= txt$ & ";" ELIF LEFT$(txt$,7) = "DECLARE" THEN txt$ = REPLACE$(txt$,"DECLARE","") txt$= txt$ & ";" ELIF INSTR(txt$, "CONCAT$") THEN txt$ = REPLACE$(txt$,"CONCAT$","strcat") txt$ = txt$ & ";" END IF IF INSTR(txt$,"LEN") THEN txt$ = REPLACE$(txt$,"LEN","strlen") amount = TALLY(txt$, "(") IF amount = 1 THEN
txt$ = txt$ & ";" END IF END IF IF INSTR(txt$,"$") THEN txt$ = REPLACE$(txt$,"$","_picoSTR") END IF Bcode$ = Bcode$ & txt$ & NL$
WEND
CLOSE FILE myfile Ccode$ = Ccode$ & Bcode$ PRINT Ccode$ SAVE Ccode$ TO HOME$ & "/test.c" LOCAL result$ result$ = EXEC$("avr-gcc " & HOME$ & "/test.c -o " & HOME$ & "/test") IF NOT(LEN(result$)) THEN IF FILEEXISTS(HOME$ & "/test") THEN PRINT "Success Now test gcc" result$ = EXEC$("gcc " & HOME$ & "/test.c -o " & HOME$ & "/test") IF NOT(LEN(result$)) THEN result$ = EXEC$(HOME$ & "/test") PRINT result$ ELSE PRINT "test not found" END IF END IF END IF END SUB
IF argc >1 THEN
bas$ = argv[1] IF FILEEXISTS(bas$) THEN handle_file(bas$) ELSE PRINT bas$ & " not exist" END IF
ELSE PRINT "basic <file>"
END IF
The File :basic.bac: needs to be in home directory /*avr-gcc Demo test ===============*/ DECLARE int s,y,x /*==================================*/ SUB test()
PRINT("Testing avr basic\n")
END SUB
FUNCTION flect$(char* brat$) TYPE char* PRINT(brat$) RETURN brat$ END FUNCTION
REM START MAIN START
LOCAL int t,s LOCAL char * str$ LOCAL char * test$ = " POP " LOCAL STRING example$[STRINGBUF * 2]
COPY(example$, "Geeks ") t = LEN(example$) s= LEN(" For Geeks\n") +1 CONCAT$(example$,test$)
IF (LEN(example$) + s < STRINGBUF*2 ) THEN CONCAT$(example$, "For Geeks\n") END IF
PRINT("%d\n",LEN(example$)) PRINT (example$)
CALL test()
str$ = CALL flect$("Hello World\n")
PRINT (str$)
FOR t = 0 TO 10 STEP 1
PRINT("%d\n",t)
NEXT
END
REM END ALL THAT
Have Fun + BR Alex Added Need basic.bac in the gui Arguments Attachments:
|
|
|
Post by alexfish on Jan 9, 2024 12:02:40 GMT 1
And So To Coding in BaCon What do We Have GPIO wise 1: RASBERRY PI* DeskTop ZERO to PI5 2: RASPBERRY PI PICO , PICO w 3: ARDUINO All done with BaCon Q: What about Arduino libs, nearly All are c++ A: BaCon can do that as well Q: About that CNCIAB , what can it do A: If Examine the general construction, it can be anything you want it to be Insperation Wise Look Up YouTube From the Me CNCIAB wood working wise :: Hobby CNC section fabricated from " Cell Aluminium Honeycomb" : and tool wise 1: cnc router/cutter/engraver 2: mini beam saw : + slot/grooving 3: laser engraver 4: Horizontal & Vertical Boring 5: ETC and all done with HERETen Years of PI:: youtube link 1 Year ago YouTubePIBR Alex
|
|
|
Post by alexfish on Jan 9, 2024 13:00:37 GMT 1
Or Watch 10 years of PI
With Peters Minimal Web Browser
'https://www.youtube.com/watch?v=8ldxmyujHK8 ' Do not choke on GTK commands OPTION PARSE FALSE
' Using GTK3 PRAGMA INCLUDE <gtk/gtk.h> PRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0`
' Using libwebkit2 PRAGMA INCLUDE <webkit2/webkit2.h> PRAGMA OPTIONS `pkg-config --cflags webkit2gtk-4.0` PRAGMA LDFLAGS `pkg-config --libs webkit2gtk-4.0`
' When pressing <enter> go to the URL SUB Goto_Url
LOCAL link$
link$ = gtk_entry_get_text(GTK_ENTRY(url)) IF LEFT$(link$, 4) <> "https" THEN link$ = "https://" & link$ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(html), link$)
ENDSUB
' Initialize GTK gtk_init(0, 0)
' Create main window window = gtk_window_new(0) gtk_window_set_title(GTK_WINDOW(window), "Minimal Web Browser in BASIC") gtk_window_set_default_size(GTK_WINDOW(window), 1280, 800) gtk_window_set_icon_name(GTK_WINDOW(window), "gtk-network") g_signal_connect_data(GTK_WIDGET(window), "delete-event", G_CALLBACK(exit), 0, 0, 0)
url_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0)
' Create entry to enter URL url = gtk_entry_new() gtk_box_pack_start(GTK_BOX(url_box), GTK_WIDGET(url), 0, 0, 1) g_signal_connect_data(GTK_ENTRY(url), "activate", Goto_Url, 0, 0, 0)
' Create HTML renderer html = webkit_web_view_new() gtk_box_pack_start(GTK_BOX(url_box), GTK_WIDGET(html), 1, 1, 1)
' Load basicprogramming by default webkit_web_view_load_uri(WEBKIT_WEB_VIEW(html), "https://www.youtube.com/watch?v=8ldxmyujHK8")
' Pack everything together and wait for event gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(url_box)) gtk_widget_show_all(GTK_WIDGET(window)) gtk_main()
Have Fun + BR Alex
|
|
|
Post by alexfish on Jan 10, 2024 22:08:36 GMT 1
Pico Touch Down Simple Blink converted to #include "pico/stdlib.h"
int main() {
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT);
while (1) {
gpio_put(LED_PIN, 1); sleep_ms(250); gpio_put(LED_PIN, 0); sleep_ms(250); }
} now have the bits to copy to the device Only comment here as regards the pico , the boot loader did not work IE it was only recognized as media no matter what IE not seen in /dev/tty* :: UPDATED Do not Do This as many sites recommend See Post Below :: normal a serial device will send info via the serial port:: else the port = not registered Hence first demo should BE hello_world The Not DoSolution:: use thonny ide select Run / configure interpreter / same here : device not recognized :: Select the named media device :: select boot loader : pico : click ; after configured , all is good In real world can now see the device : in the /dev/tty*: hence can send the command like say CIRCLE(1,1,300,300) :: pico Parses the command and passes the vars to its CIRCLE(x,y,xsize,ysize) + make the gpio pins control the machine the only connection needed is a usb cable: ++ one can store the files on the device Second Picky Now moving on to coding Attachments:
|
|
|
Post by alexfish on Jan 11, 2024 1:02:25 GMT 1
Based on the above
Bits required
Editor SEDIT.bac vte : TERMINAL.bac serial Lib serial port
& a CANVAS
New Thread PICO + *** since do not need to be On a Raspberry PI desktop only requirements : PICO SDK + Examples to get started + BaCon + want to control other gadgets
PI desktop it is an option
BR Alex
|
|
|
Post by alexfish on Jan 11, 2024 14:03:49 GMT 1
Code Wise were in serial port usb hello world also can have std serial cat /dev/ttyACM0 in the code bit only action is to PRINT "Hello.world!" needs tinyusb See Picky Attachments:
|
|
|
Post by alexfish on Jan 11, 2024 15:47:53 GMT 1
Some hug & libserialport Then next will be on the soon PICO Thread FIRST DEMO IF NEW DEVICE should be : hello_world the sdk examples, it will tell you a lot about the device esp on reboot
PRAGMA INCLUDE <libserialport.h> PRAGMA OPTIONS `pkg-config --cflags libserialport` PRAGMA LDFLAGS `pkg-config --libs libserialport`
OPTION PARSE FALSE INCLUDE "hug.bac" /* This example can be used with one or two ports. With one port, it * will send data and try to receive it on the same port. This can be * done by connecting a single wire between the TX and RX pins of the * port. * * Alternatively it can be used with two serial ports connected to each * other, so that data can be sent on one and received on the other. * This can be done with two ports with TX/RX cross-connected, e.g. by * a "null modem" cable, or with a pair of interconnected virtual ports, * such as those created by com0com on Windows or tty0tty on Linux. */
/* Get the port names from the command line. */
REM in this case edited the Example read_write from Examples in the lib
FUNCTION check(enum sp_return result) LOCAL error_message TYPE char* SELECT result
CASE SP_ERR_ARG PRINT "Error: Invalid argument." END CASE SP_ERR_FAIL error_message = sp_last_error_message() printf("Error: Failed: %s\n", error_message) sp_free_error_message(error_message)
CASE SP_ERR_SUPP PRINT "Error: Not supported." END
CASE SP_ERR_MEM printf("Error: Couldn't allocate memory.\n") END CASE SP_OK: DEFAULT RETURN result END SELECT
END FUNCTION REM ================================================ FUNCTION do_ports(char* my_portname$) TYPE STRING LOCAL res$ /* The ports we will use. */ struct sp_port *ports;
check(sp_get_port_by_name(my_portname$, &ports)) check(sp_open(ports, SP_MODE_READ_WRITE))
'Setting port to 115200 8N1, no flow control check(sp_set_baudrate(ports, 115200)) check(sp_set_bits(ports, 8)) check(sp_set_parity(ports, SP_PARITY_NONE)) check(sp_set_stopbits(ports, 1)) check(sp_set_flowcontrol(ports, SP_FLOWCONTROL_NONE))
LOCAL *tx_port = ports TYPE struct sp_port LOCAL *rx_port = ports TYPE struct sp_port
/* The data we will send. */ LOCAL data = "\n" TYPE char* LOCAL size = strlen(data)
/* We'll allow a 1 second timeout for send and receive. */ LOCAL timeout = 1000 TYPE unsigned int
/* TODO On success, sp_blocking_write() and sp_blocking_read() * return the number of bytes sent/received before the * timeout expired. We'll store that result here. */ LOCAL result TYPE int LOCAL readsize = 1024 TYPE int /* Allocate a buffer to receive data. */ LOCAL buf TYPE char* buf = malloc(readsize + 1)
/* Try to receive the data on the other port. */ result = check(sp_blocking_read(rx_port, buf, readsize, timeout))
buf[result] = '\0'; res$ = buf /* Free receive buffer. */ free(buf)
/* Close ports and free resources. */ check(sp_close(ports)) sp_free_port(ports) RETURN res$ END FUNCTION REM ==================================== SUB Read() LOCAL txt$ txt$ = do_ports("/dev/ttyACM0") IF LEN(txt$) THEN TEXT(ed,txt$) END IF END SUB
REM === MAIN ==========================
win = WINDOW("Pico",600,450) but = BUTTON("Read",100,35) ATTACH(win,but,3,6) CALLBACK(but,Read)
ed = EDIT(600,400) ATTACH(win,ed,3,50)
DISPLAY
ADDED Now got the gpio working + serial port together If new to pico :: follow docs the me uses .sh example of build.sh may find it useful ::place inside the pico dir, obvious :: need to have edit-file in the /home/pi/pico/pico-examples/hello_world , edit the serial or usb demo if want to change making this will ensure your device is seen in the devs at boot IE /dev/ttyACM0 Example of hello_world #!/bin/bash # hello.sh echo $HOME/pico cd pico-examples mkdir build cd build export PICO_SDK_PATH=../../pico-sdk cmake .. cd hello_world make -j4 # cd serial # cp hello_serial.uf2 /media/pi/RPI-RP2/hello_serial.uf2 cd usb cp hello_usb.uf2 /media/pi/RPI-RP2/hello_usb.uf2 #may need to dis-connect/re-connect the device if not seen sleep 5 ls /dev/tty* echo DONE BR Alex Picky Attachments:
|
|