Monday, November 12, 2018

YDLidar (lidar) X4 API in golang

YDLidar X4

This is a demo of the YDLidar using a golang API. The software supplied with the device only contains the drivers in C++ and the visualization tool need ROS to be installed. Since I was planning to integrate this with an existing project in golang, I decided to write a driver in Go for the lidar. The examples folder contains the usage patterns.

https://github.com/deepakkamesh/ydlidar


Saturday, June 3, 2017

Roomba Dashboard - A cli dashboard for irobot create 2

Roomba Dashboard

Background:

Roomba-Dash is a cli dashboard for the IRobot Create 2 platform. I got the roomba because I wanted to build a security robot for my home.  Since I was not familiar with the capabilities of the Roomba, I build a dashboard to understand the sensors.

Demo of the dashboard driving a Roomba.

Dashboard Details:

The dashboard is primarily used to get all the useful sensor data from the roomba. In addition it can also be used to send some of the commands to the Roomba. Particularly it can change between the different roomba modes (full, safe, passive). There are a couple of gauges that provide data about the current, volts and charge of the battery.  The batt. level gauges also provides the battery level as a percentage but shows it as a graph over time.

Motor current gauge shows the current drawn by the motors. Encoder, Rotation shows the various encoder (L,R), Radius, Angle and Distance travelled. This is requested about 3 times a second and they reset on every call. The IR code shows the IR signal that is received by omni and left, right sensors. The  cliff sensors show the signal level from the cliff sensors located beneath the roomba. In addition, if any of the sensors are triggered, they will also highlight in red. The velocity sensor shows the current velocity of the motors. The light bumper gauge shows the IR bumper signals from the 6 IR sensors across the front of the roomba. Similar to the cliff sensor gauge, this also lights up when a bump is detected. The wheel sensor tracks the wheel drops and the front bumper.


Code Build Details:

The dashboard is build in golang using termui and go-roomba libraries runs on top of a C.H.I.P single board computer. The code for the dashboard is available on github/deepakkamesh. Building the dashboard is fairly straight forward. Just download the code and 'go build bin/main.go'. Its important Download the github forked versions of these libraries or alternatively add my forked version as another remote and do a git pull. I have submitted by fixes as a pull request to the owners of the repos but yet to hear back from them. Until then either approaches outlines above should work. The second approach is preferable since it does not break the import paths.

Hardware Build Details:

The hardware uses a CHIP single board computer. Its running a headless debian version for the OS. The CHIP comes with only one usb that I needed for a webcam. So I connected the TX/RX from the headers to the connectors on the roomba. The details of how to do that are available on the roomba website. Please follow the 3.3V logic instructions as the CHIP uses 3.3v logic.

I decided to power the CHIP directly from the serial port on the Roomba which has always on power. The roomba website also has a tutorial on how to accomplish this.

In addition, I tied the BRC pin to a GPIO pin on the CHIP and I pulse it for a second every minute ti prevent the Roomba from sleeping. 

Post a comment if you have any questions. 

Thursday, August 16, 2012

Installing Facebooks FlashCache on Fedora Root


Step 1: Download and compile the flashcache

Step 2:  Install the flash cache and modules to the initramfs drive

dracut --install "flashcache_load flashcache_create flashcache_destroy flashcache_setioctl dmsetup" initramfs-3.5.1-1.fc17.x86_64.img --force

Step 2.5 Install a hook to load the flash cache volume before bootup. During initqueue/finished stage

Step3: Change the /etc/fstab and grub config to point to a new file system eg. /dev/mapper/cachedev

Step 4: Reboot and drop into dracut shell

Step 5: Create the new flashcache volume

Step 6: Reboot. 

Bare Bones instructions..email me for more.

Wednesday, December 21, 2011

Simple Programmable POV Display

I decided to develop a simple POV display keeping in line with the holiday spirit. the display can be mounted on a motor drive or used by hand.

Theory:
The POV (Persistence of Vision) displays are based on the principle that the eye cannot discern movement beyond a certain speed. For example, a fast moving light would appear to be a contiguous line. This circuit exploits this principle to flash a straight line of LEDs in rapid succession in order to create words that appear in mid air. The circuit uses a PIC 16F88 microcontroller to control seven LEDs and flashes them based on the word that was programmed.

Programming:
The project uses a single push button to program different letters into the EEPROM of the microcontroller. The push button is held down for about 5 secs to put it in programming mode. In order to enter different letters, the push button is depressed until the letter you need is reached. The letters are display in their binary format as follows:

The LEDs are represented from most significant to least significant. 0 indicates off and 1 indicates on. After the desired letter is reached, wait for a few seconds for the character to be written to EEPROM. This will be indicated by all the LEDs going off. Repeat this process to program all the characters.


A  0000001
B  0000010
C  0000011
D  0000100
E   0000101
F   0000110
G  0000111
H  0001000
I    0001001
J   0001010
K  0001011
L   0001100
M  0001101
N  0001110
O  0001111
P  0010000
Q  0010001
R 0010010
S 0010011
T 0010100
U 0010101
V 0010110
W 0010111
X 0011000
Y 0011001
Z 0011010
[space] 0011011
'0'   0011100
'1'   0011101
'2'   0011110
'3'   0011111
'4'   0100000
'5'   0100001
'6'   0100010
'7'   0100011
'8'   0100100
'9'   0100101

Friday, March 25, 2011

Hacking a Passive Infared (PIR) Sensor with a PIC


I got my hands on a quorum RR-150 PIR sensor from Electronic Goldmine. My goal was to make a receiver for the sensor. The PIR sensor uses a PT-2262 encoder chip connected with a DIP switch to generate random variations. The signal generated is 434 MHz




First things first. I needed to make sense of the signal pattern that was coming out of the PT-2262 encoder chip. I connected a RCR-433-AS receiver module to the DisCo USB oscilloscope  I took a couple of screenshots of the pattern with different DIP settings to decipher it.





The DIP switch has 6 switches out of which 2 through 6 are connected to the PT2262 encoder. The 1st switch appears to control whether the remaining 5 switches are connected to Vdd or Vss. Turning on the DIP switch sets the port to Vdd or Vss (depending on switch 1) and turning it off leaves the port floating which is detected as a distinct state by the encoder.

The output pattern looks similar to this. There is a total of 25 bits in the pattern. The last 15 bits seem similar irrespective of the DIP switch setting. So that would be the signature to look for when detecting for this particular PIR sensor.


The datasheet for PT 2622 indicates the following patterns for '1', '0' and floating








DIP switch set at: 1-off 2-off 3-off 4-off 5-off 6-off
The first 5 bits all show floating patterns.







DIP switch set at: 1-off 2-on 3-off 4-on 5-off 6-on 
Since the first switch is set to off the switches are all connected to Vss. So 'on' is represented by a '0' and a 'off' is represented by a floating pin.





DIP switch set at: 1-on 2-on 3-off 4-off 5-off 6-off
Since the first switch is on, all the switches are connected to Vdd. So 'on' is represented by '1' and off is still floating pin.


So there is it...With this, we can now detect a unique signature pattern off the PIR and also detect the DIP switch setting.


Operation:

The pic I choose for the project is a midrange 12F683. Its perfect for this project because for its compact form fact (8 pin DIP) and Timer gating capability. (Timer gating is when the timer is incremented only when there is an input on the Timer Gating pin)

In order to read these signals, The output from the RF receiver module  is connected to the T1G port of the pic. This will increment timer when the input goes high. After a full pulse is received, the pic checks to see if the pulse is a long pulse or a short pulse based on the duration of the pulse.

After determining the type of the pulse, the bit type (1, 0 or floating) is constructed  based on the sequence of the pulses. (ie. 2 shorts pulses is '0', 2 long pulses is '1', a short pulse followed by a long pulse is floating 'f') and store it in an array. Holding the push button down for 5 secs enables 'learning mode' which is used to store the code into the EEPROM. 


Schematic:


Parts List:
  • IC1 - 12F683 PIC
  • LED1 - 3mm LED
  • R1 - 220 Ohm resistor
  • R2 - 39 Ohm resistor
  • S1 - Push button switch
  • K1 - Relay (170 ohm)
  • IC2 - 78L05 5v Voltage regulator
  • C1 - 0.1uF capacitor
  • Radiotronix RCR-433-RP RF receiver module
Source code for this project is available here under GPL licence.

To request the programmed chip, click here 




    Monday, October 11, 2010

    PIC 16F88 Digital Thermometer Light Meter and resistance ohm meter.

    My original idea for this project was simply to try and interface the WINTEK WD-C2401P lcd panel to the pic (see my previous post). I figured it would be fun to add a couple of ADC readings to display something useful on the lcd. 


    Theory of Operation:


    PORTB on the PIC is used as the data port for the LCD. The Enable, Register Select and Reset are tied to PORTA. Once the LCD is initialized, the PIC reads the ADC values from the thermistor, CDS cell and resistor (if connected) via a voltage divider. The voltage divider translates any change in resistance from the sensors into changes in voltage. The Vout is calculated as 
    Vdd*(R2/R2+R1). ) So any change in R1 (the sensor's resistance) will result in a change in the output voltage. In order to translate this into the ADC value, a 10 bit ADC resolution microcontroller will have 1024 (2 to the power of 10) possible steps. So if the controller is operating on 5V then each step will increment the voltage by 5/1024 = 0.004882813V every increment. So the value in the ADC will be the voltage input at the ADC divided by 0.004882813. This allows for an accurate calculation of the resistance of the sensor. In order to translate the resistance to useful human readable form, its necessary to calibrate the sensors using real life instruments and extrapolating the values to the resistance offered. Since the display does not have any backlight, an LED is connected to PORTA4 to turn on whenever the light falls below a certain threshold. 


    Parts:
    PIC 16F88
    78L05 Voltage regulator
    C1 - 1uf capacitor
    R1,R3,R4 - 10K Ohm
    R2 - 1K Ohm
    R5 - 120 Ohm
    LED
    Thermistor
    CDS Cell
    Wintek WD-C2401P LCD display


    Circuit Diagram:

    Designed by Mindfront Technologies for    
    The complete kit is available at www.chaneyelectroincs.com

    Tuesday, September 28, 2010

    ADC Conversions on Microchip

    In order to correctly perform an ADC it is important to ensure there is enough time between enabling the ADC module to performing a conversion. Here is a code sample for PIC 16F88


    #define TEMP 0x00 //AN0
    #define LIGHT 0x08 //AN1



    ANSEL |= 0x03; //Select AN0-1 as analog
    TRISA |= 0x03; //Select RA0-1 as input
    ADCON0 =0x00; //Configure A/D params


    unsigned int GetA2DLevel(unsigned char channel)
    {
    unsigned int adc_result=0;
    ADCON1 =0b10000000; //Configure A/D params
    ADCON0 =0b11000001 | channel; //Set the channel and start A/D module
    __delay_us(20); //Delay required to ensure module is operating properly
    ADCON0 |= 0x04; //Start Conversion
    while(ADCON0 & 0x04); //Wait for conversion
    adc_result = ADRESH;
    adc_result = (adc_result<<8)|ADRESL;
    ADCON0 =0x00;

    return adc_result;

    }

    Wednesday, July 21, 2010

    Interfacing Wintek WD-C2401P LCD with Microchip PIC

     Wintek WD-C2401P LCD panel is a 24x1 character display. The code for using the LCD was written for microchip PIC 16F88 but should work with all other micro controllers.

    Pinout for the WD-C2401P

    Pin #NameFunction
    1VssGround ( 0v)
    2Vdd+5 volts
    3ResetWhen this pin is low it resets the LCD. You can either tie this pin to a pin on your microcontroller so you can reset the LCD before initializtion, or just tie it high. I had a couple of times where I couldn't init the LCD without first resetting it, so I'd recommend putting it under micro control, or some other powerup controller. The reset low time should be at least 10ms. The time after reset before you start commanding the LCD should also be at least 10 ms.
    4RSRegister Select. This pin determines whether the data you're about to write is a command or a data byte. Commands do interesting stuff to the LCD, like set the number of lines or contrast. Data is what actually gets put on the screen, or in the custom character registers. High means Data, Low means command
    5Read/WriteSet this pin high to read from the display. Set this pin low to write to it. If you don't need to update the display super fast you can save an I/O line by just tying it to ground. Wait at least a millisecond between each command and data, though, since you can't query the busy status without read capability.
    6EEnable. This line works to clock in data and commands. See the protocol section below.
    7DB0Least Significant Data Bit
    8DB1
    9DB2
    10DB3
    11DB4
    12DB5
    13DB6
    14DB7

     Details of soldering the pins are available at http://www.serialwombat.com/parts/lcd111.htm


    lcd_wintek_wdc2401p.h:
    
    #define E_LO  PORTA &= ~0x80;  //RA7
    #define E_HI  PORTA |=0x80
    #define RS_HI  PORTA |=0x40 //RA6
    #define RS_LO  PORTA &= ~0x40
    #define RESET_LO PORTA &= ~0x04
    #define RESET_HI PORTA |= 0x04
    #define LCD_DATA PORTB
    
    #define DELAY10MS __delay_ms(10)
    #define DELAY1MS __delay_ms(1)
    #define DELAY5MS __delay_ms(5)
    #define DELAY20MS __delay_ms(20)
    #define DELAY90MS __delay_ms(90)
    #define DELAY0_5MS __delay_us(500)
    #define DELAY5US __delay_us(5)
    
    void LCDInitialize();
    void LCDWriteChar(char c);
    void LCDClockByte(char c); //Called internally do not use
    void LCDClearScreen();
    void LCDWriteString(char *s);
    void LCDResetChar(); //Return back to first address
    
    
    lcd_wintek_wdc2401p.c:
    
    #include "lcd_wintek_wdc2401p.h"
    
    void LCDInitialize()
    {
    
     DELAY90MS;
     RESET_LO;
     DELAY20MS;
     RESET_HI;
     DELAY20MS;
     
     //Initialize Sequence
     E_LO;
     DELAY5US;
     RS_LO;
     DELAY1MS;
     LCDClockByte(0x1C); //Turn on the lcd driver power
     LCDClockByte(0x14); //Turn on the character display
     LCDClockByte(0x28); //Set two display lines (The hd66717 considers
         //12 characters to be a line. Our 24 character display is
         //actually two 12-character lines right next to each other).    
     LCDClockByte(0x4F); //Set to darkest contrast
     LCDClockByte(0xE0); //Set the data address to the first character
     DELAY5MS;
    }
    
    void LCDClockByte(char c)
    {
     DELAY1MS;
     LCD_DATA = c;
     E_HI;
     DELAY5US;
     E_LO;
    }
    
    void LCDWriteChar(char c)
    { 
     RS_HI;
     LCDClockByte(c);
    }
    void LCDResetChar()
    {
     RS_LO;
     LCDClockByte(0x02);
    
    }
    void LCDWriteString( char *s)
    {
     unsigned char c,i,end_flag=0;
     DELAY1MS;
     LCDResetChar();
     DELAY1MS;
     for(i=0;i< 24;i++) {
     
      c = (s[i] == 0x00)?'-':s[i];
      
      if(s[i] == 0x00 || end_flag == 1){
       c = ' ';
       end_flag = 1;
      } else {
       c = s[i];
      }
      LCDWriteChar(c);  
     }
    } 
    
    void LCDClearScreen()
    {
     RS_LO;
     LCDClockByte(0x01);
    }
    
    
    main.c: (Sample Usage)
    #include "lcd_wintek_wdc2401p.h"
    main() {
     //Make sure you setup the pins on the micro controller for output
           // and designate the pins properly in the include file. 
     char s[]="abcdefghijklmnop";
     LCDInitialize();
     LCDClearScreen(); 
     LCDWriteString(s);
    }
    

    Monday, April 19, 2010

    Zilog Microcontroller General Purpose Frequency Counter with 7 segment display

    This circuit is a frequency counter circuit original designed  to be used with a Geiger Counter.This circuit uses an 8 bit 8F0423 Zilog microcontroller to act as a frequency counter. The input to the circuit is driven through an optocoupler to isolate the source circuit. The output is displayed on a 3 digit seven segment display. There are 2 push buttons, one for reset and another to select between counter and frequency mode. Counter mode simply measures the counts whereas the frequency mode measures the counts per minute. The counter can accurately measure input up to 999,999, but only the 3 most significant digits are displayed. For example to display 19,832, 198 is displayed on the seven segment display and the x100 LED comes on. The overflow LED is used to indicate when the count has exceeded 999,999. It is fairly simple to add additional digits but for the purpose of my measurement the 3 most significant digits were sufficient. 

    Technical Details:



    The output from the optocoupler is connected to pin 11 of the microcontroller with a pull up resistor. A pull up resistor is used to ensure that there is a proper logic on the microcontroller input even when the output from the optocoupler is floating. An interrupt service routine (ISR) is triggered every time there is a transition on the port (from low logic to high logic and vice versa). The ISR keeps track of the count. Timer 1 is configured as a timer to indicate when a full minute is elapsed. This allows for the calculation of the number of transitions per minute. The 2 pins which say "To Geiger LED" take the input from any source.
     
    Driving the seven segment display:
    There are 7 LEDs per digit and to display 3 digits it will normally take 7x3 = 21 pins. This is beyond the packaging of most microcontrollers and a waste of resources. Instead a technique called multiplexing is used. Each digit on the display is turned on and off so rapidly that it gives an illusion that they are all on at the same time. This is due to the persistence of vision experienced by the eye. Timer 0 is configured to timeout every 1 ms and updates the seven segment display.
    Your browser may not support display of this image.

    Mode and reset buttons:
    The mode and reset buttons are driven by their own ISRs to interrupt every time they are pushed down.  The internal pull up resistor is enabled on the pins connected to push button switches. This is to ensure there is always a clear logic level even when the push button is off (floating). 


    Designed by Mindfront Technologies for  
    The complete kit is available at www.chaneyelectroincs.com

    Monday, April 5, 2010

    PIC 16F88 Microcontroller PIC based Tengu

    Tengu derives its name from a mythical Japanese creature known for getting into mischief. Our Tengu, however is more earthly in nature.  It responds to voice and sounds and takes on different facial features depending on the intensity of the sound. If no sound is heard for some time, it changes from a happy face to a sad face and then goes to sleep. Gently blowing on his face wakes him back up to his usual happy self. 




    The Technical Details:
    The project is based on a Microchip PIC 16F88 which is part of their mid range of microcontrollers. The sound is amplified through a pre-amp circuit based on 2N3904 and fed to the RB7/AN6 (pin 13) of the pic microcontroller. The A/D converter on the microcontroller is used to convert the analog signal from the pre-amp. The LED Matrix is directly driven by the pic. In order to be able to display the entire smiley, the LED dot matrix is multiplexed in such a way that only one row out of the seven is active at any given time. However the rows are turned on and off so rapidly, the human eye sees it as a full picture. This effect is called the persistence of vision. In order to achieve multiplexing, timer 0 on the pic is running at approximately 1 ms timeouts to switch the row that is being displayed on the LED Matrix. Timer 1 is configured as a general purpose timer used to keep track of the time since any noise over the threshold was heard. This is used to change the smiley from a happy to a sad one. The code is written in C using MPLAB and Hi-Tech C compiler ver 9.80.


    Parts List:
    • PIC Microchip 16F88
    • 7x5 LED Dot Matrix Display
    • 5 x 160 Ohm resistor
    • 2 x 10K Ohm resistor
    • 1 x 100K Ohm Resistor
    • 2N3904 NPN Transistor
    • Electret Mic
    • 1 x 0.1 uf capacitor
    • 1uf capacitor
    • 78L05 5v voltage regulator
    Circuit Diagram 
    Eagle Schematic available here

    The gain I was getting on the amp circuit above was only moderate. I changed the circuit to use a LM386 based on Jose Pino's circuit and got a much better gain. The circuit diagram is below. The 10K potentiometer is used to adjust the sensitivity of the mic while the 100K potentiometer is used to adjust the gain. 


    Designed by Mindfront Technologies for  
    The complete kit is available at www.chaneyelectroincs.com

    Here is the video of the project in action:




    YDLidar (lidar) X4 API in golang

    YDLidar X4 This is a demo of the YDLidar using a golang API. The software supplied with the device only contains the drivers in C++ an...