In the preparation for the Knitting Geeks there was a participant mentioning making a new version of the board for loading images to the KH-940 with a Teensy 3.1 instead of an Arduino Due. (The Due is used for existing board, but the shield is milled and the connections are very fragile.)
In a special geek party setting this idea was worked out.
This is a board made at a workshop of the knitic artists at Bruxelles in 2013. It had to be debugged on the hardware side. The proposed software was replaced by my own software, which mainly differed from the knitic code in that it minimized communication during knitting: https://myfablab.wordpress.com/2014/10/11/writing-my-own-software-for-the-kh-940/
New board: Hardware
Microcontroller: Teensy 3.1 with many pin’s. Many more than an Arduino! But it runs at 3.3V, while the KH-940 is at 16V for the solenoids and 5V for the sensors. Besides this board runs at a hogher CPU speed – this had consequences, see later.
This Teensy is the big difference with the knitic board version 1 and 2. These Knitic boards are mounted on an Arduino Due, expensive and bulky. The AYAB board is also mounted on an Arduino. The Teensy 3.1 is not only smaller, but cheaper (and faster – but -, see text).
The big connector – same problem: not available at Farnell. DIY! The foot was printed on a 3D printer and the pin’s were made of 1.5 mm steel wire. This worked perfectly. Two of these big connectors were made and are visible on the board: the first one in the middle was misplaced: it should be at the left, because of the short original Brother wiring.
The soldering should not have been such a problem, the set-up is simple. Just connect the ULN’s to the Teensy pin’s…But in the end the 3 ranges of voltage (3.3V, 5.0V, 16V) made it a bit of a mess.
First the 3.3V of the Teensy was tried for all pins. But the pins (encoder pins) required 5V in the end. The same for the sensors (magnetic sensors at the left and the right of the knitting machine). The Teensy digital pin’s are 5V tolerant, but not all the analog pin’s…
It was decided to work with voltage dividers for the analog sensor pin’s, adding two small (blue) potmeters. The 5V is taken from the big connector of the KH-940. The potmeters as voltage dividers make it 2.5V max for the Teensy.
This should also have been a piece of cake. The DIY software worked on the former board. (This software is different from the knitic software: it uploads the total image at once, not the lines of the image after each tour.) In this software the serial communication during knitting is reduced to the absolute minimum: if you try to send too much data to the Processing sketch during knitting, sensor data from the needles are lost, and this machine needs every bit of data!
But the Teensy is different from the Arduino Due. The default CPU speed is 96 MHz. This seems to be an advantage but is wasn’t. CPU speed at 24MHz is the only setting that seemed to work. Also the Serial port works differently, like the Leonardo. Processing starting up and connecting through Serial doesn’t reset the Teensy. This asked for a better initialize() function.
The real party was not the soldering, but in the end the re-programming. When something goes wrong you debug, one way to debug is sending control data. But it was just mentioned that the Arduino Due software worked, after reducing the sending of data. The same for the Teensy, because the problem is the data from the KH-940. After reducing communication again it worked … well sometimes. Sometimes is strange! Software shouldn’t be like that! Lot’s of debugging again.
Apparently a big part of the solution of the problem was making variables “volatile”. In compiling the C code the normal code and variables is “optimized”, shifted around etc. By adding volatile to the declaration of the variable it can be used in interrupt functions. In the Arduino Due code the functioning was stable without making the image file data “volatile”, but with the Teensy this had to be volatile to make it work.
After the volatile idea, things remained unstable.
Look at the image which shows the data sent and received back: the red pixels are wrong:
In the left picture the horizontal lines also shift the whole picture down (see the pixel signature at tour 80), this is solved by making the delay after Serial communication of “there comes a tour of pixels” larger. Then at the right you see a mistake inside a tour: this is solved by adding a delay(1), after each char received ( the tour pixels come in char’s of 8 bits). So the “glitches” of getting the image inside the Teensy are now solved.
Still sometimes the knitter just doesn’t knit the image. The solenoids are not positioned. Probably another delay which is too short during the attachement of the carriage to the belt? But in this situation there cannot be any delay added…
The fun of the KH-940 is that you can easily spend a week long party at learning to knit a sock totally manually but also head banging more than a week doing hardware things and programming!
Although it is clear now that the software is rather dependent of communication speeds (and delays), and probably nobody will make the board like i did (:-) you can find the script here:
Teensy (arduino script):