Monday, August 9, 2010

v2.0 Lucid dream aid - Eyepiece


Details shortly

v1.0 Lucid dream aid Source code

Here will be presented the source code for the lucid dream aid based on the PIC 12F683 microcontroller. This code was written in HI-TECH C lite, which is free for anyone.

/*********************************************************************
*
* Konstantin Avdashchenko Lucid dreaming aid.
*
********************************************************************/

/** I N C L U D E S **********************************************************/
#include
#include
//#include
#include "delay.h"

/** C O N F I G U R A T I O N ************************************************/

#define REDon GPIO5 = 0; GPIO4 = 1;
#define LEDoff GPIO5 = 0; GPIO4 = 0;
#define IRon GPIO5 = 1; GPIO4 = 0;

#define XTAL 4000000
#define BRATE 9600
#define TxData GPIO0 /* Map TxData to pin */

/** V A R I A B L E S ********************************************************/

unsigned short num[30];
unsigned short *ptr = &num[0];
unsigned char i,tmp,tmp1,tmp2,Pass,ni;
//unsigned char valu[];

/** P R I V A T E P R O T O T Y P E S ***************************************/
void Judge (void);
void Flash (void);
void Baud (void);
void Check (void);
void Fill (void);


/** D E C L A R A T I O N S **************************************************/
#define SCALER 10000000
#define ITIME 4*SCALER/XTAL /* Instruction cycle time */
#if BRATE > 1200
#define DLY 3 /* cycles per null loop */
#define TX_OHEAD 13 /* overhead cycles per loop */
#else
#define DLY 9 /* cycles per null loop */
#define TX_OHEAD 14
#endif
#define RX_OHEAD 12 /* receiver overhead per loop */

#define DELAY(ohead) (((SCALER/BRATE)-(ohead*ITIME))/(DLY*ITIME))


/******************************************************************************
* Function: unsigned int sendu (unsigned char chan)
*
* PreCondition: None
*
* Input: byte to send
*
* Output: uart structured byte to the rx pin of pickit2
*
* Side Effects: None
*
* Overview: sends data to uart reciever
*
* Note: None
*****************************************************************************/

void
sendu (unsigned short byte)
{
GPIO1 = 1;
DelayUs(100);
GPIO1 = 0;
i=0;
GPIO0 = 0;
Baud();
while (i!= 8){
if((byte>>i) & 1) GPIO0 = 1;
if(!((byte>>i) & 1)) GPIO0 = 0;
Baud();
i++;
}
GPIO0 = 1;
Baud();
Baud();

GPIO1 = 1;
DelayUs(100);
GPIO1 = 0;
}

/******************************************************************************
* Function: void Fill(void)
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: Fills array for checker.
*
* Note: None
*****************************************************************************/

void Fill(){
*ptr = ADRESL;
if (ptr == &num[30]){
Check();
ptr = (&num[0] -1);
}
ptr++;
}

/******************************************************************************
* Function: void Check(void)
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: Checks wether eyes are moving.
*
* Note: None
*****************************************************************************/

void Check(){
unsigned char diff, count = 0;
for (i=0;i<29;i++){
tmp1 = num[i];
tmp2 = num[i+1];
if (tmp1 >= tmp2) diff = tmp1 -tmp2;;
if (tmp2 >= tmp1) diff = tmp2 -tmp1;;
if (diff >= 2)count++;
}
if (count >= 2) Flash();
}

/******************************************************************************
* Function: void Flash(void)
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: Flashes the LED
*
* Note: None
*****************************************************************************/
void Flash(void){
i=0;
while(i <>
REDon
DelayMs(50);
LEDoff
DelayMs(30);
i++;
}
sendu(0x69);
}
/******************************************************************************
* Function: unsigned int readadc (unsigned char chan)
*
* PreCondition: None
*
* Input: char of channel to read from
*
* Output: 10 bit value of read adc
*
* Side Effects: None
*
* Overview: reads Analog signals
*
* Note: None
*****************************************************************************/

unsigned int
readadc (unsigned char chan)
{
IRon
unsigned short value;
ADCON0 = ((chan <<>
ADON = 1; // AD module enabled
DelayUs(5); // wait for conversion
GODONE = 1; // Conversion start
while(GODONE); // wait to finish
value = ADRESL; // takes the high 8 bits of 10 to reduce noise
ADON = 0; // disable module
return value;
}



/******************************************************************************
* Function: void main(void)
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: Main program entry point.
*
* Note: None
*****************************************************************************/
void main(void)
{
OSCCON = 0x60;
ANSEL = 0x34;
TRISIO = 0x04;
GPIO = 0x00;
CMCON0 = 0x07;
ADCON0 = 0x09;
// GPIO = 0x20;

tmp = 0;
while(tmp<5){
REDon
DelayMs(50);
LEDoff
DelayMs(50);
tmp++;
}

GPIO0 = 1;

// T0IE = 1;
// TMR0 = 0xE1;
// GIE = 1;

// num = 10;

/* serial sending works
unsigned short pass;

while(1){
IRon
pass = readadc(2);
LEDoff
sendu(pass);
Flash();
}
*/

//
tmp= 0;
Pass= 0;

tmp = readadc(2);
DelayMs(10);
while(1){
Pass = readadc(2);
Fill();
sendu(Pass);
DelayMs(1);
}

// continue; // let interrupt do its job
}//end main


/******************************************************************************
* Function: unsigned int Baud (unsigned long baud)
*
* PreCondition: None
*
* Input: baud rate to delay for
*
* Output: None
*
* Side Effects: None
*
* Overview: delays before sending next bit
*
* Note: None
*****************************************************************************/

void Baud (void)
{
DelayUs(140);
}

v1.0 Lucid dream aid - Paperclip style

This post will present a way to make a Paperclip-based lucid dream aid. The ingredients you will need are a SMD red led, a PIC 12F683, an IR photo-reflective sensor (CNB1302), a 5-10k ohm resistor, Paperclips, CR2032 3v battery, An Altoids case, bits of wire (in my case 26 gauge enameled wire), and lastly, something comfortable to wear while sleeping (Go Eye patch!). The ingredients for this build can be seen in the following image:

Shown above are the ingredients for the build and the frame of the device assembled. Now that we know what we need, here is the schematic/info sheet for the build:

The image above shows the schematic. Besides this schematic, I wrote down which GPIO(General Purpose I/O) must be high for the corresponding led lights. On the right, you see the table for the used ports and their associated pin numbers. The frame for the electronics was built in the following way:


An Altoids case was cut apart so that it could be soldered to the paperclip to create a solid working space. The paperclip was widened so that it would clip around the eye patch and the CR2032 battery. The header seen on the back of the device is an ICSP header used to program the device. Most of the frame is covered in tape as the frame would be tied to the positive voltage supply of the battery. In wiring the device, I used 26 AWG enameled wire to connect all the pins.
As the frame was tied to positive I had less wires to run as the components could be tied to the frame for positive voltage. The resistor I mentioned earlier is seen on top of the microcontroller (I scavenged it from somewhere, along with the red led). The following images show the assembled device from top and bottom (with its skin on) and how the device would be used, from top and bottom:




The device operates when the paperclip is clipped around the mask and the battery and a
wire from ground is placed between the negative terminal of the battery and the mask. The source code for this build will be uploaded in the next post.

Friday, December 25, 2009

Idea- Robot movement

Create a Robotics platform that moves in a particular direction when using a circular joystick. This would result in more intuitive controls, and much steeper learning curve. The Robot will travel in the direction that you point the joystick relative to the users position. With this type of system, directing the robot to go to the left would actually be telling it to travel counterclockwise around you. This type of control can be achieved using 3 antennas, Triangulation, and Phase detection. The direction from which the signal is received can be determined by analyzing the phase shifts between signals allowing the robot to determine what it's correct path of travel should be.

Tuesday, July 7, 2009

This Is the first test in my research where I read the output of a 3-axis accelerometer and record the maximum acceleration it has seen. The PIC 18f4520 that I used on the EasyPIC5 development board, was programmed to display the current readings and maximum seen value when I press the D.0 button. As you can see in the pictures above, It shows the acceleration readings for each axis, and the max seen value in the top left. This week I intend to do the compass test, provided that the code is small enough, and later, when demo is unlocked I will test the SD card write capabilities. As the SD card and the Compass module must use the same SPI connection on the PIC microcontroller, I intend to create a circuit that will use a transistor to switch the clock signal between the two devices.

Monday, June 8, 2009

Final Update of Final project




It is finished, My plans for WORLD DOMINATION!! But I digress, Here are a few pictures of my Robo-Fish. From top to bottom we have:

The Workstation:
This is where the Masterminding Happens. And no that is not a plate of eaten food, It is a plate of wet napkins that I used in lieu of a sponge to clean the soldering iron.

Bottom tier beta:
This is the main power and motor tier. Here lies the Power regulator to decrease voltage from input power of 9V to 3V for powering the motors. The resistor core seen in this picture functioned to burn off the excess power from the zener diode. Once the zener diode burned out,
I switched to using an adjustable power supply(not seen in photo). This tier also houses the Capacitors that keep the energy for when the robot isn't connected. It also has the motor and its controller which I controlled through simple serial commands. The aluminum posts and the three pin header to the right of the motor controller are used to communicate and transfer power between the two tiers. The electrical tape wrapped around the lower left tier is used to prevent other wires from touching it. It is the only shaft that is tied to 9v as the other ones are tied to ground. The three pin header transfers 5v from the microcontroller, Serial data and the reset pin connection.

Top tier:
Here we can see the Basic stamp 2 connector, the reset button, ir transmitter and ir reciever. The ir transmitter is the large black post on the right side. The ir receiver is located on the left side of the basic stamp and it is capable of detecing how far an object is away from the ir transmitter/reciever combination. The pair is capable of detecting 5 distances and responds in a increasingly nervous recation for each tier.

Finalization:
This is the completed project. Aluminum foil was originally used as the ground conductor but due to its soft nature it would deform and the robot would get stuck. I made the ground into a copper plate and it works very well now. The resistor fisherman in the background is seen fishing for the robot, which is wearing the aluminum foil hat. The hat is used to provide power to the robot.

A video of thhe robot can be seen at
http://www.youtube.com/watch?v=9X4pfTDldhA

This is the code I used for the robot: Pleaase forgive if it has a few redundencys
' {$STAMP BS2}
' {$PBASIC 2.5}


jitter VAR Byte
speed1 VAR Byte
speed2 VAR Byte
i VAR Byte
dist VAR Byte
irdet VAR Byte
irfreq VAR Word
freqsel VAR Nib



start:
LOW 0
PAUSE 2
HIGH 0
PAUSE 100
SEROUT 1, 84 , [$80,2,2]
PAUSE 2
LOW 0
PAUSE 2
HIGH 0
PAUSE 100
SEROUT 1, 84 , [$80,0,(4 ), 100]
SEROUT 1, 84 , [$80,0,(6 + 1), 100]
PAUSE 100
SEROUT 1, 84 , [$80,0,(4 ), 0]
SEROUT 1, 84 , [$80,0,(6 + 1), 0]

Main:
DO
dist=0

FOR freqsel = 0 TO 4
LOOKUP freqsel,[37500,38250,39500,40500,41500], irfreq

FREQOUT 14,1,irfreq
irdet = IN2
dist = dist+irdet
PAUSE 1
NEXT
DEBUG DEC dist

GOTO Control

LOOP ' repeat forever
END

Control:
RANDOM jitter
IF dist = 5 THEN
speed1 = jitter & 011111
ELSEIF dist =4 THEN
speed1 = jitter & 011111
ELSEIF dist =3 THEN
speed1 = jitter & 0111111
ELSEIF dist =2 THEN
speed1 = jitter & 0111111
ELSEIF dist =1 THEN
speed1 = jitter & 111111
speed1 = speed1 | 100000
ELSEIF dist =0 THEN
speed1 = jitter & %01111111
speed1 = speed1 | %01000000
ENDIF
RANDOM jitter
IF dist = 5 THEN
speed2 = jitter & 011111
ELSEIF dist =4 THEN
speed2 = jitter & 011111
ELSEIF dist =3 THEN
speed2 = jitter & 0111111
ELSEIF dist =2 THEN
speed2 = jitter & 0111111
ELSEIF dist =1 THEN
speed2 = jitter & 111111
speed2 = speed2 | 100000
ELSEIF dist =0 THEN
speed2 = jitter & %01111111
speed2 = speed2 | %01000000
ENDIF
SEROUT 1, 84 , [$80,0,(4 + (jitter >> 7)), speed1]
SEROUT 1, 84 , [$80,0,(6 + (jitter >> 7)), speed2]
PAUSE 100*dist
GOTO Main

Monday, May 18, 2009

Feel of Robot Update

I have a lot of work ahead of me. I am having problems with the transmitters and receivers I bought as they do not work properly. I will be working on them today and should have them up and running as of Wednesday. I have found a free recliner this time and intend to pick it up assuming that someone is willing to drive me. I intend to work on and complete the maze this week, so that all that would be needed would be the table. so the layout would be Maze and robot will be completed this week, and the recliner and table next week.