Welcome! Log In Create A New Profile

Advanced

sending Gcode from rpi to arduino méga via USB

Posted by souhirferjeni 
sending Gcode from rpi to arduino méga via USB
June 12, 2019 03:24AM
Hi
Can you help me please
In my project, I have to use node js in order to send Gcode file from my raspberry pi 3 B+ to an Arduino méga via USB cable...And so I can command my printer without pc need
any idea ?
VDX
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 04:52AM
... where's the problem? -- I'm doing this regularly for some of my comercial machines - sending G- and M-codes and receiving eventual feedback for handshake or reading pin status with C# or VB programs ...


Viktor
--------
Aufruf zum Projekt "Müll-freie Meere" - [reprap.org]
Call for the project "garbage-free seas" - [reprap.org]
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 05:55AM
this is my code : (I'm trying to send one line of my Gcode)
var SerialPort = require('serialport');
var port = new SerialPort('/dev/ttyS0', {
baudRate: 115200
}, function(err) {
if (err) {
return console.log('Error: ', err.message);
}
console.log("Port is open: ", port.isOpen)
});

port.on("open", function () {
console.log("open");
port.on("data", function(data) {
console.log("data received: " + data);
});
port.write("M106 S127", function(err, res) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log('message written');
});
});

but when I light up my printer no thing happens ;(

Can you send me your code please
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 06:12AM
how about a line terminating character? Doesnt look like there is one

Every gcode line needs to be terminated with a linefeed

try
port.write("M106 S127\n", function(err, res) {
VDX
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 06:14AM
... check the Baudrate - if different, nothing will happen ...

Here an excerpt of the VB-code:

    Private Sub WriteGCode(ByVal gcode As String)
        'SerialPort1.Open()
        If Not SerialPort1.IsOpen Then
            Try
                SerialPort1.Open()
                FlushPort()
            Catch ex As Exception
                MessageBox.Show("Seriellen Port nicht gefunden!")
                Exit Sub
            End Try
        End If

        FlushPort()
        SerialPort1.WriteLine(gcode)
        ReadPortOK() ' warte auf Rückmeldung "OK"
    End Sub

"SerialPort1" is a class member, predefined for port settings and basic fuctions like ".WritLine(String str)".
"FlushPort()" and "ReadPortOK()" are some of my own methodes, but not essential for the basic communication ...

Edited 1 time(s). Last edit at 06/13/2019 05:08AM by VDX.


Viktor
--------
Aufruf zum Projekt "Müll-freie Meere" - [reprap.org]
Call for the project "garbage-free seas" - [reprap.org]
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 06:41AM
Sir I am a beginner in node.js
So can you explain more please
I try this:
port.write ( « M106 S127 \ n », la fonction (err, res) {
but I still have the same problem
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 06:55AM
when I try the code this is what is shown on rpi console:

open
Port is open: true
message written
data received: Xp3????x4
data received: ???djkfd??
data received: :a:d;ms???

and then I powered up the printer
but the fan still stopped ;(
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 08:02AM
That looks like wrong baudrate

most reprap are 250000 baud
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 08:39AM
My printer is home made with arduino mega and ramps1.4
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 09:23AM
what an absolutely horrific language...

many issues...

Most important issue is every time node.js opens the serial port it resets the controller... this makes it virtually useless as a command line tool.

After much playing around I get this to work on node.js on a linux box. (don't have a raspberry pi handy)
NB I'm just turning on a external LED on pin 63 not a fan, as my test system doesn't have 12v.
But this works every time. (I configured marlin for 115200 baud)

const SerialPort = require('serialport')
const Readline = require('@serialport/parser-readline')
const port = new SerialPort('/dev/ttyACM0', { baudRate: 115200});
const sleep = require('sleep');

const parser = port.pipe(new Readline({ delimiter: '\n' }))
port.on("open", function () {
console.log("open");
console.log("Sleeping");
sleep.sleep(5);
console.log("Woke up");
});

parser.on('data', console.log)
port.write('M42 P63 S255\n');

The output
open
Sleeping
Woke up
start
echo: External Reset
Marlin 1.1.9
echo: Last Updated: 2018-08-01 | Author: ADP

....Lots of normal marlin startup stuff....

echo:  M851 Z0.00
ok
The last ok is the reply to the sent gcode command

Edited 4 time(s). Last edit at 06/12/2019 11:09AM by Dust.
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 11:15AM
thank you very much Sir...I try it by sending "M106 S127" then the fun starts running
but when I try to send other Gcode instruction like "G1 Z-1.00\n" no thing happens
I don't know why ;(
VDX
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 11:21AM
... check pin assignemnts, working ranges and endstop status - with wrong set pins, moving to "outside" the working ranges or active endstops and "TRIGGERED" endstop status, it won't move ...


Viktor
--------
Aufruf zum Projekt "Müll-freie Meere" - [reprap.org]
Call for the project "garbage-free seas" - [reprap.org]
Re: sending Gcode from rpi to arduino méga via USB
June 12, 2019 11:30AM
Z -1 is tricky.... when right after board reset.. It needs a few things setup first

Are you working in absolute or relative positioning If you don't know you need to set it
I'm going to presume relative as you probably don't want to send the hotend through the bed
G91

Also have you homed the machine, if not you need to either home or tell it where it is, after power on the printer thinks it is at 0,0,0 till told otherwise. When at Z=0 it will not move to Z=-1
G28 or G92

Then you should probably send a feed rate with the command
eg "G1 Z-1 F300\n"

As long as this doesn't trigger an endstop, it should work.

Edited 6 time(s). Last edit at 06/12/2019 12:41PM by Dust.
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 03:23AM
It's Ok I am trying now with other commands and it works well...
Other question please Sir : how Can I send the whole Gcode file ?

Can I put: port.write(file path) ?
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 03:36AM
you cant just send the file at the printer like that

It needs to wait for OK responces (there is no flow control(on ramps), so you have to wait)
It needs to look for errors

You should probabbly also implment lines number and checksums so it can detect transmission errors and overcome simple issues.
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 03:48AM
So I can't send the whole gcode file !!! ;(

it's a problem
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 04:10AM
Why dont you just use octoprint..

It provides a web page controll pannel (or use the raspary Pi screen)

and if you really want command line there is the octocmd interface
VDX
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 05:06AM
... in my C# or VB programs, I'm sending GCode files line-wise with or without handshake.

For "syncing" pin actions with moving, I'm inserting "G4 S0.01" to finish a move before starting the next action.

Here a sample without handshake in VB:

Private Sub GoToRelease()
  Using reader As StreamReader = New StreamReader("C:\KT12\GCode\#release.gcode")
    US_off() ' bei gesetztem Ultraschall-Flag alle Ultraschall-Sender ausschalten
    While Not reader.EndOfStream
      WriteGCode(reader.ReadLine)
    End While
  End Using
End Sub


Viktor
--------
Aufruf zum Projekt "Müll-freie Meere" - [reprap.org]
Call for the project "garbage-free seas" - [reprap.org]
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 05:15AM
I can't use web interface because my project is 3d printer commanded with voice
so when i say,for exemple, "lion" his gcode will be selected then sent to the arduino to print it without any intervention from me
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 08:44AM
Quote
souhirferjeni
I can't use web interface because my project is 3d printer commanded with voice
so when i say,for exemple, "lion" his gcode will be selected then sent to the arduino to print it without any intervention from me

One solution is to have lion.gcode and the other files you can print already on an SD card attached to your printer electronics. Then you can just have the Pi send command "M32 lion.gcode" over USB.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: sending Gcode from rpi to arduino méga via USB
June 13, 2019 09:57AM
No I can't do this because files must be in the raspberry then sended to arduino via usb cable
Sorry, only registered users may post in this forum.

Click here to login