terjeio / grblHAL

This repo has moved to a new home https://github.com/grblHAL
231 stars 90 forks source link

Serial GPIO #331

Closed Whitelock-MT closed 2 years ago

Whitelock-MT commented 2 years ago

Hey,

I'm swapping from using GRBL on a Arduino to GRBLHal on a teensy, on Arduino the USB serial port and the GPIO serial are hardwired together, in the teensy this is not the case, I am having trouble changing the serial connection to these pins, help/advice would be appreciated.

End goal is to use a pi as a sender.

Thanks Kindly

phil-barrett commented 2 years ago

Do I understand you correctly, you want to use the UART connection to connect as sender to grblHAL?

If so, in my_machine.h, around line 52, change: #define USB_SERIAL_CDC 2 // 1 for Arduino class library and 2 for PJRC C library. Comment out to use UART communication. to //#define USB_SERIAL_CDC 2 // 1 for Arduino class library and 2 for PJRC C library. Comment out to use UART communication. and rebuild grblHAL.

A better solution is to use ethernet but that takes a bit more work on the pi side.

Whitelock-MT commented 2 years ago

So tried that and while the USB communication stops, the Pi gets no response from the serial connection

(Also tried simple debugging on the Pi's end, it has a python script reading the serial port and if the teensy has the below code on it, then the pi receives the 'Hello' message every second)

void setup() {
  Serial1.begin(115200);
}

void loop() {
  Serial1.println("Hello");
  delay(1000);
}
phil-barrett commented 2 years ago

Stop bits and parity? 8N1, I believe. I've gotten it to work in the past with the Teensy 4.1 though not recently. Terje will probably have some ideas.

terjeio commented 2 years ago

UART communication is working for me with the latest version (and I have used it since the start for debugging so it should work with older versions too).

By default pin 0 (RX) and 1 (TX) is used. How did you wire the Pi?

Stop bits and parity? 8N1, I believe.

Correct.

phil-barrett commented 2 years ago

Do you have USB to serial converter? It might be worth trying that. Most of them have tx/rx lights so you could see if there is activity, if nothing else.

Whitelock-MT commented 2 years ago

Thats the PI's python script, (on the chance ive done something wrong there, tried many different codes to send on the chance it was wrong to send '$$'

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import serial
import time

ser = serial.Serial(
        port='/dev/ttyS0',
        baudrate = 115200,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1

time.sleep(1)
ser.write('$$')

while 1:
        x=ser.readline()
        print x

I don't have a USB to serial, though I have another teensy (and an Arduino I could try with) as well as a oscilloscope if I should just monitor the Rx/Tx pins

terjeio commented 2 years ago

Could it be the "naked Teensy" issue? Check the Wiki and this blog post.

If in alarm 10 mode (estop asserted) the controller only responds to real-time report requests - send a ? to get one.

Whitelock-MT commented 2 years ago

It does appear to be a naked teensy problem

pi@Cnc:~ $ cd Desktop/ pi@Cnc:~/Desktop $ nano serial_uart_test.py pi@Cnc:~/Desktop $ python serial_uart.py <Door:1|MPos:0.000,0.000,0.000|Bf:35,1023|FS:0,0|Pn:D>

Thanks so much the both of you.

phil-barrett commented 2 years ago

Great! Glad you got it sorted out.

By the way, if you are writing your own sender, you will want to read up in the Grbl wiki about writing a sender and in the grblHAL Wiki as well.