Prototyping the SmartChair

We didn’t know what the problem was before Joe arrived, we couldn’t get the wave shield to access the SD card, but when Joe told us that we didn’t read the instructions correctly, it was a very upsetting roadblock. We forgot to solder four wires, now that it works we came across another problem with some files not playing, which was quickly fixed by shortening the file names of the files. Another problem that arose was a software error, the code had an extra portion of the code that told the wave shield to skip a file, that was quickly fixed by removing about 3 lines of code. We are also going to instead of soldering the wires onto the circuit we are going to add female headers just in case we want to rearrange the wires at a later time. For the LV-MaxSonar- EZ1, we want to give multiple warnings so when the sensor outputs around 210 it will give the first warning and when it outputs 160 it will give a second warning. We also tested the Prototype outside, the sensors worked outside, people parted their way for the person on the wheelchair, which made testing the sensors so much easier. Our prototype is starting to come together however we still have the data values correct because we don’t want the same sound reiterating constantly

Here’s our code for the project, including all drafts and test Arduino sketches! Don’t forget that you need to install the WaveHC library from Adafruit before you try to run this code.

Awesome job today!!

The Problem that Arose Today (SmartChair)

We wanted to test the wave shield with a new SD card, but the code wouldn’t flash properly on the arduino. We tried everything from correcting the code to downloading the scripts from the official wave shield website. Hopefully our tech mentor will save the day!

Here is the errors that arose prior to flashing:

_smartChair_02.cpp:1:23: error: FatReader.h: No such file or directory
_smartChair_02.cpp:2:22: error: SdReader.h: No such file or directory
_smartChair_02.cpp:4:22: error: WaveUtil.h: No such file or directory
_smartChair_02.cpp:5:20: error: WaveHC.h: No such file or directory
_smartChair_02:6: error: ‘SdReader’ does not name a type
_smartChair_02:7: error: ‘FatVolume’ does not name a type
_smartChair_02:8: error: ‘FatReader’ does not name a type
_smartChair_02:9: error: ‘FatReader’ does not name a type
_smartChair_02:11: error: ‘WaveHC’ does not name a type
_smartChair_02.cpp: In function ‘void sdErrorCheck()’:
_smartChair_02:42: error: ‘card’ was not declared in this scope
_smartChair_02:43: error: ‘putstring’ was not declared in this scope
_smartChair_02:44: error: ‘card’ was not declared in this scope
_smartChair_02.cpp: In function ‘void setup()’:
_smartChair_02:55: error: ‘putstring_nl’ was not declared in this scope
_smartChair_02:59: error: ‘putstring’ was not declared in this scope
_smartChair_02:78: error: ‘card’ was not declared in this scope
_smartChair_02:85: error: ‘card’ was not declared in this scope
_smartChair_02:90: error: ‘vol’ was not declared in this scope
_smartChair_02:103: error: ‘vol’ was not declared in this scope
_smartChair_02:106: error: ‘root’ was not declared in this scope
_smartChair_02.cpp: In function ‘void playcomplete(char*)’:
_smartChair_02:247: error: ‘wave’ was not declared in this scope
_smartChair_02.cpp: In function ‘void playfile(char*)’:
_smartChair_02:255: error: ‘wave’ was not declared in this scope
_smartChair_02:259: error: ‘f’ was not declared in this scope
_smartChair_02:259: error: ‘root’ was not declared in this scope
_smartChair_02:260: error: ‘putstring’ was not declared in this scope
_smartChair_02:265: error: ‘wave’ was not declared in this scope
_smartChair_02:265: error: ‘f’ was not declared in this scope
_smartChair_02:266: error: ‘putstring_nl’ was not declared in this scope
_smartChair_02:271: error: ‘wave’ was not declared in this scope

Our Goals for the SmartChair

User Exp
Approaching moving or stationery objects but doesn’t say if its moving because it doesn’t matter
Warns user to prevent from going out into the street
Warns distance of the curb from the current location of the User
Tells the distance of the building from the User
Wheel-alignment sensor
User input(a button that will potentially tell the User which direction they are going)
ON/OFF SWITCH

Side Goals:
Tells the user which side the curb would be
Tell the user how long they have before they hit the object or curb

We also finished the code and recordings for the user portion of the project, we ran into a little trouble with the circuit working, we think it could be because we used a SDHC card instead of a SD card, tomorrow we are going to test it with a regular SD card, if it is the circuit itself, Joe will be our savior and make a second working circuit!

Here is the code that Joe worked on

#include
#include
#include
#include “WaveUtil.h”
#include “WaveHC.h”

SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we’re play

WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 5 // button debouncer

// here is where we define the buttons that we’ll use. button “1” is the first, button “6” is the 6th, etc
byte buttons[] = {
3,4,5,6,7,8};
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or ‘pressed’ (the current state
volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

int currTrack = 0;

// this handy function will return the number of bytes currently free in RAM, great for debugging!
int freeRam(void)
{
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) – ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) – ((int)__brkval);
}
return free_memory;
}

void sdErrorCheck(void)
{
if (!card.errorCode()) return;
putstring(“\n\rSD I/O error: “);
Serial.print(card.errorCode(), HEX);
putstring(“, “);
Serial.println(card.errorData(), HEX);
while(1);
}

void setup() {
byte i;

// set up serial port
Serial.begin(9600);
putstring_nl(“WaveHC with “);
Serial.print(NUMBUTTONS, DEC);
putstring_nl(“buttons”);

putstring(“Free RAM: “); // This can help with debugging, running out of RAM is bad
Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble!

// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

// pin13 LED
pinMode(13, OUTPUT);

// Make input & enable pull-up resistors on switch pins
for (i=0; i< NUMBUTTONS; i++) {
pinMode(buttons[i], INPUT);
digitalWrite(buttons[i], HIGH);
}

// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
if (!card.init()) { //play with 8 MHz spi (default faster!)
putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
sdErrorCheck();
while(1); // then 'halt' – do nothing!
}

// enable optimize read – some cards may timeout. Disable if you're having problems
card.partialBlockRead(true);

// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one :(
putstring_nl("No valid FAT partition!");
sdErrorCheck(); // Something went wrong, lets print out why
while(1); // then 'halt' – do nothing!
}

// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?

// Try to open the root directory
if (!root.openRoot(vol)) {
putstring_nl("Can't open root dir!"); // Something went wrong,
while(1); // then 'halt' – do nothing!
}

// Whew! We got past the tough parts.
putstring_nl("Ready!");

TCCR2A = 0;
TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;

//Timer2 Overflow Interrupt Enable
TIMSK2 |= 1<<TOIE2;

playcomplete("hello.WAV");
}

SIGNAL(TIMER2_OVF_vect) {
check_switches();
}

void check_switches()
{
static byte previousstate[NUMBUTTONS];
static byte currentstate[NUMBUTTONS];
byte index;

for (index = 0; index 10){
currTrack = 0;
}
}

// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}

void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring(“Couldn’t open file “);
Serial.print(name);
return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl(“Not a valid WAV”);
return;
}

// ok time to play! start playback
wave.play();
}

Our First Tech Mentor Meeting(Smart Chair)

We are discussing how we would want the SmartChair to function. We are comparing different types of sensors for each task we want our prototype to accomplish. We are dividing the functionalities of the chair in inputs and outputs. The questions that arrise is “What types of input is needed?” “How will we output this data?” “What data will the User need?”. Our tech mentor, Joe Saavedra, explained to us the input/ sensors that we will be most likely be using:
Accelerometer
Infra Red Sensor
Magnetometer(aka Compass)
Sonar Sensor(Ultra Sonic)
The output would be through audio communications, as well as tactile vibrations to aid in the user’s communication with the SmartChair
Our team is hopefully going to start tinkering with our prototype by the next tech meeting which will be on Monday April 9 at 2PM