TinyG + Raspberry Pi

Home Forums TinyG TinyG Projects TinyG + Raspberry Pi

Tagged: , ,

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #3881
    burnsb
    Member

    In the beginning stages of building a cnc mill.  Plan to use a Raspberry Pi as the front end.

    In order to save on usb ports on the Rpi I connected the TinyG to the Rpi’s GPIO, bypassing the ftdi chip.  They are both running at 3V logic levels.  (The Rpi does recognize the usb connection, it comes up as /dev/ttyUSB0 and functions as below with minicom)

    To do this, one must disable the Rpi boot and shell through serial. See here: http://elinux.org/RPi_Serial_Connection

    Then at the command prompt enter:
    sudo minicom -b 115200 -o -D /dev/ttyAMA0
    Currently using minicom to spin motors and check things out.  On the TinyG I set Enable CR on TX to $ec=1 to get better formatting from the TinyG.

    I powered up the TinyG after running minicom, as it supposedly sends modem initialization garbage upon being ran.  I haven’t dug in and looked into this yet.

    #3883
    alden
    Member

    That’s great. Thanks for documenting this. Please let us know how this project goes.

    Alden

    #3948
    burnsb
    Member

    Got python on the Rpi talking to the TinyG.

    I should add that I’m using the Adafruit version of Raspbian, Occidentalis which has enhanced low-level hardware support.

    After freeing up the uart as in my above post, install the python-serial routines. (Same process to install minicom, you must have network connection to install either of these. Although there are ways of doing it with manually downloaded packages)

    At a command prompt enter:

    <code>sudo apt-get install python-serial</code>

    Before I was able to get python-serial to work I had to reboot the Rpi.  I suspect that the port was not free due to prior minicom use.

    In IDLE I created a new file.  Note, don’t name it serial.  It will try to import the current file if you do.

    test code:

    <code>

    import serial

    serialport = serial.Serial(“/dev/ttyAMA0”, 115200, timeout=0.5)

    serialport.write(“\r”)

    serialport.write(“?\r”)

    response = serialport.readlines(None)

    print str(response)
    </code>

    When the port is opened by python, it sends the TinyG an x character.  I haven’t figured out where this is coming from.
    Next up is learning about JSON, how to use python’s JSON interpreter, and learning enough python to do what I want.

    I hope in the next few weeks to begin a blog with an overview of my garage/shop and journal the build process.  Particularly relevant developments to the TinyG I will repost here if that is okay.

    End goals:
    I plan to build a CNC mill/printer.  It will have removable heads such that either a milling spindle or 3d printer head may be used.  When in milling configuration it will have available table mounted 4th axis for rotary milling capability.  The bed will be mounted to the X axis, Y and Z axis on a bridge. Raspberry Pi based gui frontend for the TinyG incorporating the various features of CNC controls I like.  I want to take from the feature sets of Fanuc, HAAS, Fadal, and even a couple of things from the Acramatic series.  I want to build a pendant that in addition to a handwheel, controls most machine functions.  Somewhat like the later Cincinnati or HAAS pendants.  It will interface through spi to the Rpi.

    To these ends I have a Atlas 6″ lathe with milling attachment, and an asian floormount drill press, and various other power and hand tools. 4 3.4V 2.0A NEMA23 steppers in the 100 oz/in range.

    #4155
    rickkaye
    Member

    I am trying to control my TinyG from a Raspberry Pi. Unlike the OP, I am connecting them through a USB cable (/dev/ttyUSB0). Using minicom on the RP, I can’t get the TinyG to respond. When I press the reset button on the TinyG, minicom sees the TinyG output, so I know the connection is good. The TinyG also responds fine when I connect it to my Mac over USB.

    I was wondering if you had any thoughts on what might be wrong. Thanks.

    Rick

    #4157
    alden
    Member

    Not sure what’s going on. TinyG needs a standard 115,200 setup
    – 115,200 baud, 8 data bits, 1 stop bit, no parity.

    If you are going to stream to it from the terminal emulator you should also enable XON/XOFF on both tinyg and the terminal emulator.

    #4159
    rickkaye
    Member

    Yes, I had it set to 115,200 8N1. Since I couldn’t get minicom to work, I moved on to controlling the TinyG with a python script as burnsb described above. That worked perfectly. Then I just tried the command line command
    echo g0x100 > /dev/ttyUSB0
    and that worked. So, the minicom failure is still a mystery. Now, I will write a C program to control the TinyG which is my ultimate goal anyway.

    #4164
    alden
    Member

    Good news. Please let us know if you find out why minicom didn’t work.

    -Alden

    #4206
    burnsb
    Member

    Sorry for the late post. Still working on this project. Currently have the Rpi talking json to the tg. Working on gui stuff with tkinter.

    As far as minicom goes, I’ve quit using it. Instead I’ve been using miniterm:
    pi@raspberrypi /usr/bin $ miniterm.py -e –cr /dev/ttyAMA0 115200

    • This reply was modified 11 years, 3 months ago by burnsb. Reason: formatting
    #4221
    rickkaye
    Member

    Thanks for the update. miniterm works here over USB:

    miniterm.py –cr /dev/ttyUSB0 115200

    #4415
    lalee
    Member

    When using Minicom, the easiest way to check that communications is working is to press Ctrl-X (“reset TinyG”), and possibly Ctrl-M and Ctrl-J to force a carriage-return and linefeed.

    You should be able to get a response.

    While Minicom is not an “official” method, I have found it to be usable enough to do ASCII uploads of GCode files with a few setting tweaks.

    I have a writeup on my blog along with my thoughts on what may be a root-cause in the TinyG firmware preventing ASCII uploads via Minicom or even a “cat [filename] > /dev/ttyUSB0” from working.

    In a nutshell, disabling echo, status verbosity, and text verbosity should keep the line free for TinyG to transmit flow-control characters unimpeded. If you want extra reliability, drop the baud rate to 38400.

    • This reply was modified 11 years, 1 month ago by lalee. Reason: blog link got eaten by wp?
    #4417
    liseman
    Member

    Any luck getting OctoPrint controlling a synthetos tinyg CNC via a raspberry pi? I’m seeing the output in ‘terminal’ when I issue commands by echoing directly over usb, but octoprint sticks at ‘connecting.’

    #4418
    burnsb
    Member

    lalee- very cool.

    liseman- I’m not famillar with OctoPrint, but what distro are you using and what are your port settings?

    I haven’t had much time to work on this lately (been doing piecework with my lathe on the weekends for extra money).

    Last thing I did was getting a tinyg state loaded into python, i.e. all co-ords, active codes, etc. Having trouble with some sort of overflow. I’m at work and can’t remember exactly what the issue was, but it seemed to be an error on the pi side. I may try slowing down the baud as lalee suggests.

    #4443
    lalee
    Member

    I’ve not had experience with OctoPrint, so I can’t comment on that specifically. The requirements list for running it kind of turned me off.

    I’ve had tough luck with Raspberry Pi. The linux usb driver (dwc_otg) is some of the shoddiest funk I’ve ever had the displeasure of fixing. Try running a HD webcam off the USB port, and the USB driver falls apart at the seams. It also doesn’t help that the RPi folks refuse to acknowledge there’s a problem, even though they’ve hired a guy to specifically work on that code since January. *Sigh*, hopefully it gets better soon.

    At the moment, I’m knee-deep into enhancing the TinyG firmware to operate a ShapeOko/TinyG based 3D printer – at least something usable enough to print up the parts I need for my next machine. ‘Wish TinyG was MIT-licensed to continue forward with it on the next machine build, but can understand the desire to restrict commercial use. I’ll have to go clean-room for the next machine’s hardware/firmware combo.

    Anyway, while glossing over the TinyG firmware code, I noticed the serial buffers are on the small side at only 256 bytes. After recompiling with each direction’s buffer bumped up to 1K, I seem to be getting reliable results at 115K on my v6.

    #4444
    burnsb
    Member

    Fwiw, I bypassed the usb on both the Rpi and the Tinyg, and instead used the Rpi and Tinyg uart. As they are both 3v logic I just connected up the two lines and ground. I did this because I didn’t want to add a usb hub to be able to use X.

    It wouldn’t surprise me if the broadcom hardware uart was superior to the Raspbian software serial routines.

    #6708
    Zootalaws
    Member

    So… it’s been a year. How did this project end up?

    I am just in the throes of building an OpenBuilds Ox and already have a couple of Pi’s around for Octoprinting my 3D printer, so am interested in the results.

    Running tgFX for Tiny control would be the aim, connected over ethernet.

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.