Skip to content

Commit

Permalink
Merge pull request #54 from aj-ptw/dev-3.0.0
Browse files Browse the repository at this point in the history
Dev 3.0.0
  • Loading branch information
AJ Keller authored Jun 17, 2017
2 parents 6bd10e9 + f53e9ae commit 5bbf05a
Show file tree
Hide file tree
Showing 15 changed files with 627 additions and 919 deletions.
File renamed without changes.
729 changes: 438 additions & 291 deletions OpenBCI_32bit_Library.cpp

Large diffs are not rendered by default.

57 changes: 34 additions & 23 deletions OpenBCI_32bit_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class OpenBCI_32bit_Library {

typedef enum BOARD_MODE {
BOARD_MODE_DEFAULT,
BOARD_MODE_DEBUG
BOARD_MODE_DEBUG,
BOARD_MODE_ANALOG,
BOARD_MODE_DIGITAL
};

typedef enum PACKET_TYPE {
Expand Down Expand Up @@ -93,6 +95,7 @@ class OpenBCI_32bit_Library {
void deactivateChannel(byte); // disable given channel 1-8(16)
void disable_accel(void); // stop data acquisition and go into low power mode
void enable_accel(byte); // start acceleromoeter with default settings
const char* getBoardMode(void);
char getChannelCommandForAsciiChar(char);
char getCharSerial0(void);
char getCharSerial1(void);
Expand All @@ -101,6 +104,7 @@ class OpenBCI_32bit_Library {
char getDefaultChannelSettingForSettingAscii(byte);
char getGainForAsciiChar(char);
char getNumberForAsciiChar(char);
const char* getSampleRate(void);
char getTargetSSForConstrainedChannelNumber(byte);
char getYesOrNoForAsciiChar(char);
boolean hasDataSerial0(void);
Expand All @@ -113,18 +117,17 @@ class OpenBCI_32bit_Library {
void leadOffSetForChannel(byte, byte, byte);
void ledFlash(int);
void loop(void);
void printSerial(uint8_t);
void printSerial(uint8_t c, uint8_t arg);
void printSerial(uint8_t *, size_t len);
void printSerial(const char *data) {
printSerial((uint8_t *)data, strlen(data));
}
void printlnSerial(uint8_t);
void printlnSerial(uint8_t c, uint8_t arg);
void printlnSerial(uint8_t *, size_t len);
void printlnSerial(const char *data) {
printlnSerial((uint8_t *)data, strlen(data));
}
void printAll(const char *arr);
void printlnAll(const char *arr);
void printlnSerial(void);
void printlnSerial(char);
void printlnSerial(int);
void printlnSerial(int, int);
void printlnSerial(const char *);
void printSerial(int);
void printSerial(char);
void printSerial(int, int);
void printSerial(const char *);
boolean processChar(char);
void processIncomingBoardMode(char);
void processIncomingSampleRate(char);
Expand All @@ -139,11 +142,12 @@ class OpenBCI_32bit_Library {
void stopADS(void);
void sendChannelData(void);
void sendChannelData(PACKET_TYPE);
void setBoardMode(uint8_t);
void setChannelsToDefault(void);
void setCurPacketType(void);
void setSampleRate(uint8_t newSampleRateCode);
void sendEOT(void);
void setSerialInfo(SerialInfo si, boolean rx, boolean tx, uint32_t baudRate);
void setSerialInfo(SerialInfo, boolean, boolean, uint32_t);
boolean smellDaisy(void);
void streamSafeChannelDeactivate(byte);
void streamSafeChannelActivate(byte);
Expand All @@ -161,15 +165,21 @@ class OpenBCI_32bit_Library {
void updateDaisyData(boolean);
void useAccel(boolean);
void useTimeStamp(boolean);
void wifiAttach(void);
void wifiSetInfo(SpiInfo, boolean, boolean);
boolean wifiStoreByte(uint8_t);
void wifiFlushBuffer(void);
boolean wifiAttach(void);
void wifiBufferTxClear(void);
void wifiBufferRxClear(void);
void wifiFlushBufferTx(void);
void wifiReadData(void);
uint32_t wifiReadStatus(void);
void wifiRemove(void);
boolean wifiRemove(void);
void wifiReset(void);
void wifiSendGains(void);
void wifiSendStringMulti(const char *);
void wifiSendStringLast();
void wifiSendStringLast(const char *);
void wifiSetInfo(SpiInfo, boolean, boolean);
boolean wifiSmell(void);
boolean wifiStoreByteBufTx(uint8_t);
void wifiWriteData(uint8_t *, size_t);
void write(uint8_t);
void writeAuxDataSerial(void);
Expand Down Expand Up @@ -216,9 +226,9 @@ class OpenBCI_32bit_Library {
short auxData[3]; // This is user faceing
short axisData[3];

uint8_t wifiBuffer[WIFI_SPI_MAX_PACKET_SIZE];
char wifiBufferInput[WIFI_SPI_MAX_PACKET_SIZE];
uint8_t wifiBufferPosition;
uint8_t wifiBufferTx[WIFI_SPI_MAX_PACKET_SIZE];
char wifiBufferRx[WIFI_SPI_MAX_PACKET_SIZE];
uint8_t wifiBufferTxPosition;

unsigned long lastSampleTime;

Expand Down Expand Up @@ -269,12 +279,12 @@ class OpenBCI_32bit_Library {
void LIS3DH_writeAxisDataForAxisWifi(uint8_t);
void LIS3DH_updateAxisData(void);
void LIS3DH_zeroAxisData(void);
boolean processCharWifi(char character);
void printADSregisters(int);
void printAllRegisters(void);
void printFailure();
void printHex(byte);
void printRegisterName(byte);
void printSampleRate(void);
void printSuccess();
void processCharWifi(uint8_t);
void RDATA(int); // read data one-shot
Expand Down Expand Up @@ -323,6 +333,7 @@ class OpenBCI_32bit_Library {
int numberOfIncomingSettingsProcessedChannel;
int numberOfIncomingSettingsProcessedLeadOff;
int numberOfIncomingSettingsProcessedBoardType;
int wifiAttachAttempts;
uint8_t optionalArgCounter;
unsigned long timeOfLastRead;
unsigned long timeOfWifiToggle;
Expand Down
9 changes: 8 additions & 1 deletion OpenBCI_32bit_Library_Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@
#define OPENBCI_TIME_SET '<'
#define OPENBCI_TIME_STOP '>'

/** Wifi Stuff */
#define OPENBCI_WIFI_ATTACH '{'
#define OPENBCI_WIFI_REMOVE '}'
#define OPENBCI_WIFI_STATUS ':'

/** Possible number of channels */
#define OPENBCI_NUMBER_OF_CHANNELS_DAISY 16
#define OPENBCI_NUMBER_OF_CHANNELS_DEFAULT 8
Expand Down Expand Up @@ -378,6 +383,8 @@
#define WIFI_SPI_CMD_STATUS_READ 0x04
#define WIFI_SPI_CMD_STATUS_WRITE 0x01
#define WIFI_SPI_MAX_PACKET_SIZE 32
// #define WIFI_SPI_BYTE_ID_POS 31
#define WIFI_SPI_MSG_LAST 0x01
#define WIFI_SPI_MSG_MULTI 0x02
#define WIFI_SPI_MSG_GAINS 0x03

#endif
87 changes: 73 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ void setup() {
}
```

#### Bare board
```Arduino
void setup() {
board.begin(); // Bring up the OpenBCI Board
}
```

### <a name="loop"></a> loop():

We will start with the basics here, and work our way up... The loop function can be thought of as the meat and core executor of the OpenBCI_32bit_Library functionality. Keep in mind the main purpose of this library is to stream data from the ADS1299 to the computer, that's our focus, everything takes a back seat to that.
Expand Down Expand Up @@ -233,30 +226,96 @@ Called when the board ADS1299 has new data available. If there is a daisy module

## <a name="enums"></a> ENUMS:

### PACKET_TYPE_ACCEL
### BOARD_MODE

Board mode changes the hardware pins.

#### BOARD_MODE_DEFAULT

`0` - Board will operate leave all pins in default mode.

#### BOARD_MODE_DEBUG

`1` - Board will output serial debug data out of the external serial port.

#### BOARD_MODE_ANALOG

`2` - Board will read from `A6` (`D11`), `A7` (`D12`), and `A8` (`D13`). `A8` is only is use when there is no wifi present. The analog to digital converter is 10bits and the data will be in .

|Pin|Aux Bytes|Notes|
|----|----|----|
|`A6`|0:1|`D11`|
|`A7`|2:3|`D12`|
|`A8`|4:5|`D13` - If wifi not present|

#### BOARD_MODE_DIGITAL

`3` - Board will read from `D11`, `D12`, `D13` (if wifi not present), `D17`, and `D18` (if wifi not present).

|Pin|Aux Byte|Notes|
|----|----|----|
|`D11`|0||
|`D11`|1||
|`D13`|2|If wifi not present|
|`D17`|3||
|`D18`|4|If wifi not present|

### PACKET_TYPE

#### PACKET_TYPE_ACCEL

`0` - End of standard stream packet.

### PACKET_TYPE_RAW_AUX
#### PACKET_TYPE_RAW_AUX

`1` - End of stream packet with raw packet.

### PACKET_TYPE_USER_DEFINED
#### PACKET_TYPE_USER_DEFINED

`2` - End of stream packet, user defined.

### PACKET_TYPE_ACCEL_TIME_SET
#### PACKET_TYPE_ACCEL_TIME_SET

`3` - End of time sync up with accelerometer stream packet.

### PACKET_TYPE_ACCEL_TIME_SYNC
#### PACKET_TYPE_ACCEL_TIME_SYNC

`4` - End of time synced stream packet.

### PACKET_TYPE_RAW_AUX_TIME_SET
#### PACKET_TYPE_RAW_AUX_TIME_SET

`5` - End of time sync up stream packet.

### PACKET_TYPE_RAW_AUX_TIME_SYNC
#### PACKET_TYPE_RAW_AUX_TIME_SYNC

`6` - End of time synced stream packet.

### SAMPLE_RATE

#### SAMPLE_RATE_16000

`0` - Sample rate 16000Hz

#### SAMPLE_RATE_8000

`1` - Sample rate 8000Hz

#### SAMPLE_RATE_4000

`2` - Sample rate 4000Hz

#### SAMPLE_RATE_2000

`3` - Sample rate 2000Hz

#### SAMPLE_RATE_1000

`4` - Sample rate 1000Hz

#### SAMPLE_RATE_500

`5` - Sample rate 500Hz

#### SAMPLE_RATE_250

`6` - Sample rate 250Hz
34 changes: 33 additions & 1 deletion UPGRADE_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
# OpenBCI 32bit Upgrade Guide

The purpose of this document is to provide instruction, resources, and advice for upgrading an OpenBCI 32bit 8-16 channel board firmware.
The purpose of this document is to provide instruction, resources, and advice for upgrading an OpenBCI Cyton 8-16 channel board firmware.

## Upgrading to 3.0.0

### Upgrading from 2.x.x

Flash the `Pic` with [`DefaultBoard`](https://github.com/OpenBCI/OpenBCI_32bit_Library/blob/master/examples/DefaultBoard/DefaultBoard.ino)

#### Awesome New Features

* Wifi shield support
* Read from analog or digital ports in a single line or command. (board mode)
* Simplified user experience
* Variable sample rate with wifi shield or Serial1 (with baud of 468000)

#### What this update set out to solve

* Have a single `.sendChannelData()` data function to call that manages the stop byte behind the scenes. I.e. if accel data should be added to aux bytes vs. reading from analog input pins and putting that in the aux bytes.
* Add wifi support without breaking any firmware v2.0.0 or v1.0.0 features.
* Prevent users from having to upload custom code to the pic

#### In depth tutorials
* [How to get/install/upload code to Pic32 `Board`](http://docs.openbci.com/tutorials/02-Upload_Code_to_OpenBCI_Board#upload-code-to-openbci-board-32bit-upload-how-to-firmware-version-2xx-fall-2016)

#### New commands

* [Set Board Mode]()
* [Set sample rate]()
* [Wifi attach/remove/status]()

### Upgrading from 1.x.x

Read *Upgrading to 2.0.0* below:

## Upgrading to 2.0.0

Expand Down
19 changes: 15 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

### New Features

* Add wifi shield support
* Send channel gains to wifi shield at start of stream
* takes ~4 seconds for the wifi shield to be reachable
* Add ability to turn external serial port `Serial1` on through commands.
* Add ability to use ESP8266 through SPI port.
* Change board types on the fly!
* Add loop function for internal timing operations
* Add function to turn time stamps on `useTimeStamp(true)`, time stamps are disabled by default.
* Change board types on the fly! No longer do you have to upload new code to the Cyton's Pic32 just to do an analog read. You can now read from analog or digital pins with the press send of a code! `/` now sets the board mode, where:
* BOARD_MODE_DEFAULT is `0`
* BOARD_MODE_DEBUG is `1`
* BOARD_MODE_ANALOG is `2`
* BOARD_MODE_DIGITAL is `3`
* Add loop function for internal timing operations related to power on reset for wifi shield, remove `loop` to free up pins and such and remove wifi capability.
* Add function to turn time stamps on `useTimeStamp(true)`, time stamps are disabled by default. Note the Wifi shield will use NTP time stamps.
* Add wifi commands:
* _OpenBCI Wifi Attach_ - `{`
* _OpenBCI Wifi Remove_ - `}`
* _OpenBCI Wifi Status_ - `:`

### Enhancements

* `hasDataSerial0` and `hasDataSerial1` use new properties `SerialInfo` to determine if data should be received. Now safe to call every loop.

### Breaking Changes

* Removed boolean `useAccel` in support of new mode paradigm. To use the accel, do nothing, it's enabled by default, to not use the accel simply call `useAccel(false)` and send the contents of `auxData` array each packet.
* Removed boolean `useAccel` in support of new mode paradigm. To use the accel, do nothing, it's enabled by default, to not use the accel simply call `useAccel(false)` and this library will automatically send the contents of `auxData` array each packet.
* Removed `OPENBCI_EOP_STND_ACCEL`, `OPENBCI_EOP_STND_RAW_AUX`, `OPENBCI_EOP_USER_DEFINED`, `OPENBCI_EOP_ACCEL_TIME_SET`, `OPENBCI_EOP_ACCEL_TIME_SYNCED`, `OPENBCI_EOP_RAW_AUX_TIME_SET`, and `OPENBCI_EOP_RAW_AUX_TIME_SYNCED` in place of `enum` support replacement: `PACKET_TYPE_ACCEL`, `PACKET_TYPE_RAW_AUX`, `PACKET_TYPE_USER_DEFINED`, `PACKET_TYPE_ACCEL_TIME_SET`, `PACKET_TYPE_ACCEL_TIME_SYNC`, `PACKET_TYPE_RAW_AUX_TIME_SET`, and `PACKET_TYPE_RAW_AUX_TIME_SYNC`.
* Removed `sniffMode` in place for `curBoardMode == OPENBCI_BOARD_MODE_DEBUG`
* Removed public `waitForNewChannelData()`
Expand Down
16 changes: 9 additions & 7 deletions examples/BoardWithAnalogSensor/BoardWithAnalogSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
#include <OpenBCI_32bit_Library.h>
#include <OpenBCI_32Bit_Library_Definitions.h>

// NOTE: THIS DOES NOT HAVE SD

void setup() {
// Bring up the OpenBCI Board
board.begin();

// Notify the board we want to use aux data, this effects `::sendChannelData()`
board.useAccel(false);
// Read from the analog sensor and store auxiliary position 0
// take a reading from the ADC. Result range from 0 to 1023
// Will put 10 bits from:
// Aux 1:2 D11 (A5)
// Aux 3:4 D12 (A6)
// Aux 5:6 D17 (A7)
board.setBoardMode(BOARD_MODE_ANALOG);
}

void loop() {
Expand All @@ -19,12 +26,7 @@ void loop() {
// Read from the ADS(s), store data, set channelDataAvailable flag to false
board.updateChannelData();

// Read from the analog sensor and store auxiliary position 0
// take a reading from the ADC. Result range from 0 to 1023
board.auxData[0] = analogRead(A7);

// Send standard packet with channel data and aux data
// includes aux data because we set `useAux` in setup()
board.sendChannelData();
}
}
Expand Down
Loading

0 comments on commit 5bbf05a

Please sign in to comment.