The whole project have 2 main software component, one is on the Arduino, the other is a uploading program on the desktop.
The Arduino software consists of a set of library and the main program.
The libraries consist of 2 part, one is the storage class, and the word generation class. They can be found at https://github.com/sweemeng/storybox/tree/master/libraries/storyboard
The original implementation of the storage class, WordStorage is using the Arduino internal EEPROM. This is while we are waiting for the Jordan finalize the I2C to external EEPROM, and waiting for the EEPROM to arrive. So this help us to create a standard interface that we use for retrieving word from storage. And we can start work early without waiting. What we learn here is there is a slight delay needed for writing into the EEPROM. Because of this, it is incorporated into the class, just so that it make things easy.
The word generation class, WordGenerator, is the main engine behind selecting words from the EEPROM. From early on we decided on using the delimiter ‘:’. During testing, our member Mats have discovered that reading a large amount of words from EEPROM can take a lot of time. This prompt us to create a simple lookup table on the beginning of the eeprom, based on the idea by Adam. The idea behind the lookup table is.
|bit 0||bit 1||bit 2||bit 3|
We allocated a amount of N * 4 byte in the beginning of the EEPROM. Each stores the beginning position and ending position of a group of word along with their delimiter which is ‘:’. In the Arduino code, we use 7. We should have around 28 bit allocated for the header. Each with the beginning position and ending position of the word group we stored into the EEPROM. And this is generated by the uploading program, not on the Arduino.
The word group is selected randomly, so instead of select a random word one by one. Then another random select on the word group is done to select a word, within the segment of EEPROM selected. . By randomly select a char within the group, and find the next delimiter, and that consider as the first character, and the next delimiter from it is the last character. We store the beginning position and ending position.
The main program then on a press of a button, call word selection, and from the beginning character, to the ending, read the character one by one from EEPROM, and send it to the LCD.
The function to write to eeprom, will just read from serial and write to EEPROM, without preprocessing, as the preprocessing is already done on the uploading program
The PC program
The GUI version of the program to upload the words to the arduino shield is not complete. But a test program that runs on python shell is completed. The reason we use python is because the time it take to write a program is shorter. It will preprocess the word group, and size. and from it, send the processed data over serial to Arduino.
What we’ve learned:
- Use serial, serial connection remain the most reliable way to send debugging information to the Arduino, it would be the equivalent to print in other programming languages.
- One of the biggest gotcha that we found is a slight delay is needed for writing to external EEPROM.
- Have access to hardware to test the code on is important. This help us to find and capture all issues early
- And have abstract out some component is helpful to get us started early too.
Share this article
Here’s the BOM list for StoryBox. For this challenge, all of the participating hackerspaces were provided USD900 by the organizer (thanks element14!). To be frank, we didn’t used up all of the money. In fact, we don’t need to use it as we have most of the components available at our space. However, we did spent some amount buying an LCD (yo element14, your LCDs are really expensive, we got a few from Jalan Pasar for less than RM20!) and a few EEPROMs.
|1||AT24CXXB-PU||1||IC1||Atmel I2C EEPROM. XX: from 01 to 1024||12.4|
|2||2N3904||2||Q1, Q2||NPN transistor||0.5|
|3||16X2 LCD Module||1||LCD||LCD module, 16X2 Alphanumeric||20|
|4||Trimmer – 1k||1||R6||LCD backlit brightness||0.5|
|5||Trimmer – 4k7||1||R7||LCD contrast||0.1|
|6||Resistor 1k||3||R2, R3, R4||0.1|
|9||Ceramic Capacitor 100nF||1||C1||Non polarity capacitor||0.1|
|11||Tact Switch – N.O||1||S1||Any momentarily Normally Open push button||0.1|
|12||Protoshield||1||Breadboard, veroboard or custom made PCB||3|
So we spent RM109, roughly USD36.