Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
13 KiB

  1. It is fun to find an interesting use for old technology. Being someone who has
  2. tons of old floppy drives and loves music, I decided to turn my old floppy
  3. drives into an orchestra. I’m not sure where I first learned about musical
  4. floppy drives, however, there are thousands of videos on YouTube.
  5. This project first started over a year ago when I connected two floppy drives to
  6. a Raspberry Pi to play the Star Wars theme.
  7. <youtube src="wcnUvPMpqjA" />
  8. Although this was fun, there was hardly any software for playing different music
  9. on the Raspberry Pi. I managed to hack the software to also play Jingle Bells,
  10. however, that took hours to input just a single song.
  11. A half a year ago I got an Arduino board and built a new and improved floppy
  12. drive orchestra.
  13. <youtube src="qwbcrR-6dTU" />
  14. What is nice about using an Arduino, is that the software used is more
  15. developed. Unlike the program I used with the Raspberry Pi, the software used
  16. with the Arduino allows the songs to be loaded via a MIDI file.
  17. That brings us up to the present. My previous 8 floppy drive orchestra was not
  18. transportable and took up a ton of space. When I decided to present this project
  19. at Imagine RIT with RITlug, I knew I had to rebuild my orchestra to be portable
  20. and compact.
  21. There are plenty of tutorials online demonstrating how to build floppy
  22. orchestras, but, many of them are incomplete. Since this was my third time
  23. building a floppy orchestra, I decided to log my process and make a complete
  24. tutorial for my blog.
  25. Hardware
  26. ========
  27. - 10 Floppy Drives
  28. - Arduino Uno
  29. - LOTS of Ribbon Cables
  30. - 1 Old Power Supply
  31. - Hot Glue
  32. - Solder
  33. In in addition to these materials, you will also want something to mount your
  34. floppy drives to. I decided to use 2x2’s and half inch screws because they are
  35. cheep and I had some laying around my house.
  36. Assembly
  37. ========
  38. The first thing you should do is secure your floppy drives.
  39. ![Floppy Drives](media/f8802f1f71cb433274d265fc81e36fc6.jpg)
  40. Now, it is time to power the floppy drives and turn them on. To make the floppy
  41. drives turn on, you need to connect pins 11 and 12 on your floppy drives
  42. together. You can easily do this with a single ribbon cable.
  43. ![Floppy Drives pin configuration](media/5b7a15fd7b5da2939f4e27eae4ceada3.jpg)
  44. ![Floppy drives connected together](media/09bce0ed13f28db38a141bd10bb096c8.jpg)
  45. You can use an old power supply for this project. Since we are only using the
  46. stepper motor in the floppy drives, you only need to supply 5v. Each floppy
  47. drive has four power connectors, the middle two pins are ground, and the right
  48. pin is 5v and the left pin 12v. Since I had ten floppy drives to power, I used a
  49. bread board to avoid excessive soldering.
  50. To turn on a power supply you simply connect the green wire to any ground wire.
  51. If you want to get fancy, you can solder on a switch, however, must people just
  52. jam a paper clip into the motherboard connector.
  53. FWI: The red wires in your power supply are 5v and the black wires are ground.
  54. **Warning**: Do not draw all your power from the power supply via a single
  55. ribbon cable, it will melt. Ribbon cables have low gauge and are not meant for
  56. high wattages. It is good idea to use multiple 5v lines from your power supply
  57. and make sure that nowhere in your wiring is all the voltage going through a
  58. single ribbon cable.
  59. ![Musical floppy drives wired together](media/5ebac37ad45784c31219451d6e4c4504.jpg)
  60. If you have done everything correct up to this point, you will see the green
  61. lights on the floppy drives turn on when the power supply is running.
  62. Now we need to connect the pins of the floppy drive to the Arduino.
  63. Personally, I started by connecting pin 19 on the floppy drive to the ground pin
  64. on the Arduino. Again, I used a bread board to make the connections easier.
  65. ![Floppy drives pin io](media/d0888a3222fa328c291629fac491e268.jpg)
  66. ![Floppy drives connected to uno](media/463f2aa188466da8f47309235039250c.jpg)
  67. Next, we need to wire the step and direction pins of the floppy drives to the
  68. Arduino.
  69. ![Floppy drives pin diagram](media/81ffef0249da3c1fc077d114fb6beecb.jpg)
  70. Connect direction pin 18 on the floppy drive to pin 3 of the Arduino and step
  71. pin 20 to pin 2 of the Arduino. For additional floppy drives you follow the same
  72. pattern. For example, the next drive would be floppy pin 18 to Arduino pin 5 and
  73. floppy pin 20 to Arduino pin 4. If you are using something other than an Arduino
  74. Uno board this will potentially be different. We are using these specific pins
  75. on the Arduino because they correspond to this specific program.
  76. ![Floppy drives wired together with power supply](media/50dc96254f26b730e842134db98c9966.jpg)
  77. While making this, I had 4 sets of pins (8 total) connected to the Arduino,
  78. however, I have 10 floppy drives in total. I wired two sets of three drives and
  79. two sets of two drives together on the same Arduino “channel”. This makes the
  80. wiring easier and makes the sound better. Not all floppy drives sound the same,
  81. by pairing drives together you get a richer sound. Since I want to present this
  82. live, it also makes it louder for the audience.
  83. This is a ton of wiring! After you verify that the drives are working properly,
  84. I would strongly recommend using hot glue to secure ribbon cables to the drives.
  85. That’s it. Now your floppy drives should be good to go.
  86. Software
  87. ========
  88. This is the section where most other tutorials fall short. Please follow along
  89. carefully. First, have the following installed on your computer.
  90. - Arduino Software
  91. - NetBeans
  92. - JDK 1.8 – or higher
  93. Next download
  94. [timer1](https://code.google.com/archive/p/arduino-timerone/downloads) and
  95. [Moppy](https://github.com/SammyIAm/Moppy). Install timer one by extracting the
  96. files and copying the folder timer1 into the libraries folder under your root
  97. Arduino directory.
  98. Open up your Arduino software and paste the following code in the editor:
  99. ```
  100. #include <TimerOne.h>
  101. #define RESOLUTION1 40
  102. boolean firstRun = true; // Used for one-run-only stuffs;
  103. //First pin being used for floppies, and the last pin. Used for looping over all pins.
  104. const byte FIRST_PIN = 2;
  105. const byte PIN_MAX = 17;
  106. /*NOTE: Many of the arrays below contain unused indexes. This is
  107. to prevent the Arduino from having to convert a pin input to an alternate
  108. array index and save as many cycles as possible. In other words information
  109. for pin 2 will be stored in index 2, and information for pin 4 will be
  110. stored in index 4.*/
  111. /*An array of maximum track positions for each step-control pin. Even pins
  112. are used for control, so only even numbers need a value here. 3.5" Floppies have
  113. 80 tracks, 5.25" have 50. These should be doubled, because each tick is now
  114. half a position (use 158 and 98).
  115. */
  116. byte MAX_POSITION[] = {
  117. 0,0,158,0,158,0,158,0,158,0,158,0,158,0,158,0,158,0};
  118. //Array to track the current position of each floppy head. (Only even indexes (i.e. 2,4,6...) are used)
  119. byte currentPosition[] = {
  120. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  121. /*Array to keep track of state of each pin. Even indexes track the control-pins for toggle purposes. Odd indexes
  122. track direction-pins. LOW = forward, HIGH=reverse
  123. */
  124. int currentState[] = {
  125. 0,0,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW
  126. };
  127. //Current period assigned to each pin. 0 = off. Each period is of the length specified by the RESOLUTION1
  128. //variable above. i.e. A period of 10 is (RESOLUTION1 x 10) microseconds long.
  129. unsigned int currentPeriod[] = {
  130. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  131. };
  132. //Current tick
  133. unsigned int currentTick[] = {
  134. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  135. };
  136. //Setup pins (Even-odd pairs for step control and direction
  137. void setup(){
  138. pinMode(13, OUTPUT);// Pin 13 has an LED connected on most Arduino boards
  139. pinMode(2, OUTPUT); // Step control 1
  140. pinMode(3, OUTPUT); // Direction 1
  141. pinMode(4, OUTPUT); // Step control 2
  142. pinMode(5, OUTPUT); // Direction 2
  143. pinMode(6, OUTPUT); // Step control 3
  144. pinMode(7, OUTPUT); // Direction 3
  145. pinMode(8, OUTPUT); // Step control 4
  146. pinMode(9, OUTPUT); // Direction 4
  147. pinMode(10, OUTPUT); // Step control 5
  148. pinMode(11, OUTPUT); // Direction 5
  149. pinMode(12, OUTPUT); // Step control 6
  150. pinMode(13, OUTPUT); // Direction 6
  151. pinMode(14, OUTPUT); // Step control 7
  152. pinMode(15, OUTPUT); // Direction 7
  153. pinMode(16, OUTPUT); // Step control 8
  154. pinMode(17, OUTPUT); // Direction 8
  155. Timer1.initialize(RESOLUTION1); // Set up a timer at the defined resolution
  156. Timer1.attachInterrupt(tick); // Attach the tick function
  157. Serial.begin(9600);
  158. }
  159. void loop(){
  160. //The first loop, reset all the drives, and wait 2 seconds...
  161. if (firstRun)
  162. {
  163. firstRun = false;
  164. resetAll();
  165. delay(2000);
  166. }
  167. //Only read if we have
  168. if (Serial.available() > 2){
  169. //Watch for special 100-message to reset the drives
  170. if (Serial.peek() == 100) {
  171. resetAll();
  172. //Flush any remaining messages.
  173. while(Serial.available() > 0){
  174. Serial.read();
  175. }
  176. }
  177. else{
  178. currentPeriod[Serial.read()] = (Serial.read() << 8) | Serial.read();
  179. }
  180. }
  181. }
  182. /*
  183. Called by the timer inturrupt at the specified resolution.
  184. */
  185. void tick()
  186. {
  187. /*
  188. If there is a period set for control pin 2, count the number of
  189. ticks that pass, and toggle the pin if the current period is reached.
  190. */
  191. if (currentPeriod[2]>0){
  192. currentTick[2]++;
  193. if (currentTick[2] >= currentPeriod[2]){
  194. togglePin(2,3);
  195. currentTick[2]=0;
  196. }
  197. }
  198. if (currentPeriod[4]>0){
  199. currentTick[4]++;
  200. if (currentTick[4] >= currentPeriod[4]){
  201. togglePin(4,5);
  202. currentTick[4]=0;
  203. }
  204. }
  205. if (currentPeriod[6]>0){
  206. currentTick[6]++;
  207. if (currentTick[6] >= currentPeriod[6]){
  208. togglePin(6,7);
  209. currentTick[6]=0;
  210. }
  211. }
  212. if (currentPeriod[8]>0){
  213. currentTick[8]++;
  214. if (currentTick[8] >= currentPeriod[8]){
  215. togglePin(8,9);
  216. currentTick[8]=0;
  217. }
  218. }
  219. if (currentPeriod[10]>0){
  220. currentTick[10]++;
  221. if (currentTick[10] >= currentPeriod[10]){
  222. togglePin(10,11);
  223. currentTick[10]=0;
  224. }
  225. }
  226. if (currentPeriod[12]>0){
  227. currentTick[12]++;
  228. if (currentTick[12] >= currentPeriod[12]){
  229. togglePin(12,13);
  230. currentTick[12]=0;
  231. }
  232. }
  233. if (currentPeriod[14]>0){
  234. currentTick[14]++;
  235. if (currentTick[14] >= currentPeriod[14]){
  236. togglePin(14,15);
  237. currentTick[14]=0;
  238. }
  239. }
  240. if (currentPeriod[16]>0){
  241. currentTick[16]++;
  242. if (currentTick[16] >= currentPeriod[16]){
  243. togglePin(16,17);
  244. currentTick[16]=0;
  245. }
  246. }
  247. }
  248. void togglePin(byte pin, byte direction_pin) {
  249. //Switch directions if end has been reached
  250. if (currentPosition[pin] >= MAX_POSITION[pin]) {
  251. currentState[direction_pin] = HIGH;
  252. digitalWrite(direction_pin,HIGH);
  253. }
  254. else if (currentPosition[pin] <= 0) {
  255. currentState[direction_pin] = LOW;
  256. digitalWrite(direction_pin,LOW);
  257. }
  258. //Update currentPosition
  259. if (currentState[direction_pin] == HIGH){
  260. currentPosition[pin]--;
  261. }
  262. else {
  263. currentPosition[pin]++;
  264. }
  265. //Pulse the control pin
  266. digitalWrite(pin,currentState[pin]);
  267. currentState[pin] = ~currentState[pin];
  268. }
  269. //
  270. //// UTILITY FUNCTIONS
  271. //
  272. //Not used now, but good for debugging...
  273. void blinkLED(){
  274. digitalWrite(13, HIGH); // set the LED on
  275. delay(250); // wait for a second
  276. digitalWrite(13, LOW);
  277. }
  278. //For a given controller pin, runs the read-head all the way back to 0
  279. void reset(byte pin)
  280. {
  281. digitalWrite(pin+1,HIGH); // Go in reverse
  282. for (byte s=0;s<MAX_POSITION[pin];s+=2){ //Half max because we're stepping directly (no toggle)
  283. digitalWrite(pin,HIGH);
  284. digitalWrite(pin,LOW);
  285. delay(5);
  286. }
  287. currentPosition[pin] = 0; // We're reset.
  288. digitalWrite(pin+1,LOW);
  289. currentPosition[pin+1] = 0; // Ready to go forward.
  290. }
  291. //Resets all the pins
  292. void resetAll(){
  293. // Old one-at-a-time reset
  294. //for (byte p=FIRST_PIN;p<=PIN_MAX;p+=2){
  295. // reset(p);
  296. //}
  297. // New all-at-once reset
  298. for (byte s=0;s<80;s++){ // For max drive's position
  299. for (byte p=FIRST_PIN;p<=PIN_MAX;p+=2){
  300. digitalWrite(p+1,HIGH); // Go in reverse
  301. digitalWrite(p,HIGH);
  302. digitalWrite(p,LOW);
  303. }
  304. delay(5);
  305. }
  306. for (byte p=FIRST_PIN;p<=PIN_MAX;p+=2){
  307. currentPosition[p] = 0; // We're reset.
  308. digitalWrite(p+1,LOW);
  309. currentState[p+1] = 0; // Ready to go forward.
  310. }
  311. }
  312. ```
  313. ![Arduino program screenshot](media/23c6ad380e3224fbcd0c8d28cbecac23.png)
  314. Now you can upload this script to your Arduino.
  315. ![Arduino Uno serial COM settings](media/0b9d25d56269d39f60177b6b29a882da.png)
  316. If you get any errors about your COM port, make sure that your Arduino is set to
  317. listen on COM1 under the Device manager –Windows only.
  318. If that works, you can now open Moppy through Netbeans and start playing with
  319. your musical floppy drives.
  320. ![Moppy control application](media/161edc628257e8a2f92086c5987dcf0f.png)
  321. For a great package of MIDI music to use check out
  322. [MrSolidSnake](https://github.com/coon42/Floppy-Music--midis-). Not all MIDI
  323. songs work well with floppy drives. Songs with too many tracks obviously won’t
  324. work well. Songs with high notes will sound terrible on floppy drives since they
  325. will grind their motors. Also, long notes don’t sound good because the floppy
  326. drives just spin back and forth. MrSolidSnake did a wonderful job at compiling a
  327. bunch of MIDI files that work’s well with floppy drives.
  328. I hope that this tutorial was helpful.
  329. <youtube src="X0FeJPFKpQw" />