Welcome! Log In Create A New Profile

Advanced

Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi

Posted by lhartmann 
Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 12, 2016 01:19AM
This is not a question, this is me bragging I did it! A working proof of concept! :-D Below is a video of it running 3 steppers with acceleration profiles and independent speed.

[www.youtube.com]

A little while ago I realized an I2S digital sound output looks a lot like a SPI output, and SPI outputs can drive shift registers. back then I was focused on the ESP8266, so I build a small 32 bit shifter board based on 4x 74H595 and wrote a realtime bitbanger demonstrating it as a GPIO expansion (see [forums.reprap.org]). Then, a couple of days ago I found a few post of people using I2S DACs to improve sound quality on single-board-computers, more specifically Raspberry Pi and Orange Pi. Then it hit me:

I2S is a realtime digital output present on most SBCs, and we may use may shifter board to control a printer with it!

I just happened to have an idle Orange Pi One at hand and a few days to spare, so decided to try it out.

Code is here: [github.com]
Shifter PCB was previously released here: [github.com]

What was done:
- Replaced /boot/bin/orangepione.bin with the included fex file, so as to enable and configure I2S output.
- A C++ program renders motion for 4 steppers (only 3 connected on the video).
- The C++ program outputs 32 bit words, a bitmask for step/direction of several steppers.
- alsa player (aplay) feeds the 32bit words directly to the "sound card" (not really a card, part of the SOC).
- The "soundcard" outputs raw I2S, and feeds a 32bit shift register. Sample rate is 192k words/s.
- Just 5 wires from OrangePi to the shfter: GND, 3.3V, I2S-Data, I2S-BitClock, I2S-WordClock.
- Shifter outputs drive the stepper drivers. Bits 0-3 are STEP, bits 16-20 are DIR.
- I let out a tear of happiness. :'-D

What could we do with this:
- Discard the arduino-like controllers used on pretty much every single motion control board out there.
- Remove distinction of software and firmware, as they would run on the same processor. (Eases development).
- Make printer software mostly hardware independent, as long as there is I2S and alsa on the backend.
- Modify reprap-firmware to be more OS-friendly, and run as a backend on the *Pi.
- Have a quad-core computer running accurate motion control for the crazyest of mechanics, at high sample rates.
- Theoretical limit of 46 steppers (2 channels, 24 bit per channel, using 2 bits for a secondary shifter for DIR bits).
- Have a vision feedback system for calibration? OpenCV?
- Have a full-blown linux system control your printer:
- python, nodejs, octoprint, and whatnot providing web/touch interfaces.
- Fast uploads, as there is no serial link anywhere.
- A really nice interface to the printer: OpenGL and HDMI displays.
- Real easy updates, apt-get style.

Required for a working printer, but not tested:
- I2S input via alsa-record could allow parallel-in serial-out shift registers to read 32 bit data.
- Temperature reading via RC charge time?
- Endstops, and a few buttons.

Edited 3 time(s). Last edit at 07/12/2016 11:44PM by lhartmann.
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 12, 2016 02:34AM
Wow! I have Orange Pi one layinh around, too!!! Have to test this.
Btw, for analog in you'd be better with i2c, wouldn't you?
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 12, 2016 11:53PM
I2C has completely slipped my mind while posting this. A dedicated ADC would definitely be more accurate, but how about price?

I am already regretting getting the one. It is nice, but I am missing the 3 USB ports and the wifi of the Orange Pi PC+... In order to use octoprint+wifi+webcam I already need an USB hub. :-/

Next step: Finding out how to run RepRapFirmware on Linux.

P.S.: Updated the video, a commented version. I did not realize that mobile platforms and chromecast do not show video comments...

Edited 1 time(s). Last edit at 07/12/2016 11:54PM by lhartmann.
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 13, 2016 12:57AM
Well, for the One, I do not regret it - I have the webcam that connects directly to the board, I connect the printer directly to the 26pin header, so still I do have the USB port free. However I do not use wifi as it was a bit unreliable for me, so I vonnect the Ethernet...
But I see your point.
I have to google a bit, but I remember having i2c chip with 8ADC and 1 DAC, but only with 8bit resolution. So I have to search some more. That chip was, however, under $2.
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 13, 2016 01:00AM
This was my first googling attempt:
4channel 12bit I2C adc

Edited 1 time(s). Last edit at 07/13/2016 01:01AM by rklauco.
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 13, 2016 01:13AM
For me, this looks like a way to go: ADS1115
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 13, 2016 07:21AM
Yup ADS1115 seems like a really good choice. 16 bit resolution is almost overkill. Ordered one just in case, but china packages take 20-180 days to deliver here...

Another option would be to use 555 analog timers in astable configuration, but with the NTC as one of the resistors. If I2S inputs work as I hope they will then I may be able to find out the NTC resistance by reading the timer period.

I may have some other I2C or SPI ADCs lying around too... Will give it a try once I get some spare time again. I'm pretty sure those are expensive models, though...
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 14, 2016 11:35PM
Just tested I2S loopback to see if I2S input is possible: Good news, IT IS! (probably) spinning smiley sticking its tongue out

For now I just tested wiring I2S data output pin back to I2S data input. I also tried pulling the wire and it stopped working, so this is not an internal loopback. Since I2S-IN and I2S-OUT share the same clocks it will probably work fine with a 74HC165 shifter. I'll try making a pcb for these soon.

For the test I used 2 processes: reader and writer. See [github.com]
- The writer.cpp just writes a tag (0x11223344) then 127 words (32 bit) of a continuous counter.
- The reader.cpp looks for the tag, then checks if the following 127 words are a correct counting.

Issues:
- I could not yet get these working on the same process (loopback.cpp), loosing data. A thread or proper use asynchronous IO with select(...) should probably do the trick.
Re: Controlling a Printer With a Soundcard (I2S) on a Raspberry or orange Pi
July 15, 2016 04:55AM
My 165 set is still somewhere in China, so I cannot help for now sad smiley
But I am looking forward to it!
Excellent job, @lhartmann!
Sorry, only registered users may post in this forum.

Click here to login