💾 Archived View for consensus.circumlunar.space › arduino › serial_disk.txt captured on 2024-03-21 at 14:49:31.
⬅️ Previous capture (2020-09-24)
-=-=-=-=-=-=-
# Serial Disk My first arduino project. I'm probably more excited about this than I ought to be. First, some impressions: 1. Arduino is way easier than is legally allowed. You can build stuff that would have taken months, in minutes. 2. The hardware is dirt cheap. I don't know how reliable it is, but boy howdy, this stuff is affordable. It's also easy to get. It's almost too good to be true. 3. Whoever is designing Arduino hardware must know what hobbyists want and need. They're doing it right, I feel, in terms of having a product that people actually want. ## The Project On to the actual project. This is related to my z80 projects- specifically, to my prototype board z80 computer with ROM BASIC based on Grant Searle's "Simple z80" design. In that project, the computer has rom basic and a serial port, and nothing else. You boot it up, write your code, and play, then start over when you power on the next day. The system was fun, but I wanted storage so desperately. I built a new clock circum and a cassette interface, and cobbled together the ability to LOAD/SAVE from cassette at 300 baud. It was a beautiful thing, and it almost worked. I say almost; it worked, but it wasn't super reliable, and it was so slow. I could live with the slow (there's a certain charm to it!) but the reliability was a killer. I don't want to deal with corrupt recordings. The solution, in my mind, was this: build a small box that you can connect to the z80's serial port, which upon pressing a button will type "LIST<enter>" and record the output to a file on an SD card, then display a list of files and let you select one and press "LOAD" to send it to the serial port. Basically, a serial port disk device, for storage. Then, I could use my z80 computer somewhat independantly (meaning, without my laptop powered on), *and* have mass storage. Ideally, the device would run at 115200, the native speed of the z80 build. ## The Build At first, I thought I might be able to figure some solution out from scratch. I'm quite certain this is possible. Unfortunately, time and knowledge were not on my side toward this end. I settled on the idea of Arduino, something I'd always wanted to try anyway. My first testing was with an Uno that I had laying around from a thrift store find. It had everything I needed to fiddle. I got an i2c 16x2 LCD working, and that was incredibly simple and fast. I ordered an SD adapter; that worked too, with very little hassle. Next I tried out a few different types of buttons, and settled on a 1-pin analog solution, which I soldered up with a few buttons and resistors. Then I hit a small roadblock: the Uno has only one serial connection, and it's shared with the programmer (as I understand it). I ordered a Mega 2560 for a couple bucks on ebay, changed the code a tiny bit, and I'm off again. Connected up a TTL-RS232 that I had around, and now the thing has a DB9 serial port of the correct gender for my project. With a tiny bit of coding (I've not done C++ for a long time!), the thing works as expected, which is: - You power the unit, the LCD displays version info and init info - After successful init, the LCD lets the user know the unit is ready - You may press < or > to navigate the files on the SD card - You may press "LOAD" to send the selected file from SD to Serial at 115.2k (with a tx character delay of 6ms, which my board needs) - You may press "SAVE" to send "list<enter>" over the serial and then recieve characters and save them to a new incremented file. The result is mass storage usable with the z80 computer and without another computer in the mix (as long as you don't count the arduino. It's cheating compared to the cassette interface, but I don't care. I'm in this to have fun!) All that remains, as far as the build goes, is to get it into a suitable enclosure. ## The Code DISCLAIMER: There is nothing impressive below. Like I said, I've not done C++ in a while, and even when I did it wasn't that great. I'm not a programmer, just a hobbyist. If you have tips about the code, please send them my way! The code Works(TM). It's simple, and it uses the pre-built libraries for the bits of hardware I'm using. I believe this is the Arduino Way(TM). I've included comments, to hopefully make things a little more readable. This runs on Mega 2560, but it runs with very few changes on Uno as well (though, I'm not entirely sure about the Serial conflicts on Uno). /* * Serial Disk v0.6 * * A serial disk program for z80 (or other) serial console computers. * Useful for saving/loading ROM BASIC programs, file transfers, etc. * Public domain, tfurrows@sdf.org, 10/21/2019 On Arduino Mega 2560 ==================== SD to SPI: CS - pin 4 MOSI - pin 51 MISO - pin 50 SCK - pin 52 I2C 16x2 LCD: SDA - pin 20 SCL - pin 21 Analog Buttons 1-5 to A1 (using 5 2k resistors; adjust values as needed) TTL->232 4-pin: RX - pin 14 RX - pin 15