cgnuino
Public Member Functions | List of all members
CgnStrobe Class Reference

Emits a text as one-by-one characters using (8 + 1)-bit digital-out. More...

#include <cgnuino.h>

Public Member Functions

 CgnStrobe (byte, uint32_t=5)
 Constructor. More...
 
uint32_t out (String)
 Emits arbitrary text by (8 + 1)-bit digital outputs. More...
 

Detailed Description

CgnStrobe is a rather peculiar facility compared with other classes in this library. It converts arbitrary length of text to 8-bit digital outputs, and emits it by strobing the other one digital-out pin. This can be used to emit event timing signal in a good time resolution, maintaining the differentiation of multiple event identities.

In implementing behavioral tasks with Arduino, experimental data are supposed to be saved to a text file on the PC through a USB serial. In serial communication, emitted texts are designed to be first buffered and wait for a short period to be actually sent. This delay is typically less than several milliseconds, and possibly dozens of milliseconds even at maximum. Still a serial is regarded as unreliable for strict event timing outputs for this buffering problem.

To put out strict timing signal, you can use a mere digital outputs from Arduino. The rising/falling edge of digital signal can be captured by external data acquisition device practically without any delay. Although this method is a classic in sending event timing , it is somewhat unsophisticated since this kind of digital outputs cannot hold information other than the timing. In other words, a single line of digital signal cannot tell what event is taken place. For example, if there are 10 different events in your task (e.g., trial start, cue on, cue off, response start, button press, etc...) you need 10 digital-out pins to mark the occurrences of these possible events individually.

To overcome these weak points, you can combine event timing marks by a digital output and multi-bit binary representation of characters. For example, you can express 256 different combination of 0/1 bit pattern using eight digital pins. Which bit pattern corresponds to what character is actually universal for standard English characters as Ascii table (http://www.asciitable.com/).

+ 0 1 2 3 4 5 6 7 8 9
3x! "#$%&'
4x( ) * + , - ./ 0 1
5x2 3 4 5 6 7 8 9 : ;
6x< = > ? @A B C D E
7xF G H I J K L M N O
8xP Q R S T U V W X Y
9xZ [ \ ] ^ _ ` a b c
10xd e f g h i j k l m
11xn o p q r s t u v w
12xx y z { } ~

Each row corresponds tens place and column ones place. As shown in the table, standard English characters are represented by values ranging from 0 to 127. For example, upper "A" corresponds to 65, and lower "a" corresponds to 97. The value 97 is expressed as 1100001 in binary representation (i.e., 64 + 32 + 1). Therefore, you can express a letter "a" by pulling up the 8th, 7th and 1st bits of the 8-bit set of digital-out pins. However, changing all the eight digital-out pins simultaneously, accurately in microsecond order, is somewhat an uncertain operation. This is why you need the last 9th bit for precise temporal timing. You first change the eight digital-out pins to represent an arbitrary character, and when ready, pull up the 9th pin. This works as a strobe light in photography, and enables temporally accurate transmission of a character. And by repeating 8-bit change and 9th bit rise (and then fall, of course), you can send any length of text you want, but only one-by-one at a time.

Some commercial data acquisition devices have receiver mechanism of this character representation. (I personally created this class to use it with Power1401 device from CED.) By using CgnStrobe class with those kind of devices, you can transmit texts easily and temporally more accurate way compared with a USB serial connection.

Examples:
Strobe.ino.

Constructor & Destructor Documentation

CgnStrobe::CgnStrobe ( byte  firstPin,
uint32_t  strobeUs = 5 
)
Parameters
firstPinFirst pin number for digital-out pins.
strobeUsLength of each character in [us] (MICRO-seconds).

Member Function Documentation

uint32_t CgnStrobe::out ( String  txt)
Parameters
txtText to be put out.
Examples:
Strobe.ino.

The documentation for this class was generated from the following files: