Laser Lasers

Cheap 40W Chinese Laser … quick start.

I understand these lasers come with a variety of different software packages. I bought my laser off eBay from this listing: http://www.ebay.com/itm/-/141690337410?roken=cUgayN&soutkn=EWCTN4  there are more for the purchasing.

I was having a speed issue while raster etching.. I hadn’t really done much besides burn some lines, etc.. well I found this issue. So here is my ultra-quick start-up guide.

      1. Unpack everything outside.. its a freaking styro-mess! Bring a vacuum with a hose attachment to clean out the laser. Also.. probably a solid garbage can.
      2. Install LaserDRW from the disc.. I couldn’t use my laptop disc drive, didn’t have one on my new laptop.. had to use a full size DVDROM in my workbench PC because the disc had a label.. so it wouldn’t read correctly in very thin laptop drives.. you’ve probably seen that before; I have. After LaserDRW install CorelDraw 12… using the key they provide in the .rar file… I’m sure this is a completely legit copy………  or I hear newer CorelDraw also works, I wouldn’t know.
      3. Plug the USB key into your PC… kind of annoying who wants to rip off cheap-o software?
      4. Launch CorelLASER .. this launches CorelDraw but with a tool bar in the upper right.
      5. Draw or import something like an SVG into CorelDraw then in the upper corner open the Engraving or Cutting icon and you get a screen that looks a lot like this:
        laserdraw
      6. The “Speed” is the speed of the cut/grave.. I started cutting at 30, 150 for engrave.. they’re good places to start. The lower right arrow jog the laser … too bad the arrow buttons don’t work. Repeat is the number of passes.. I like to pass multiple times on lower power if possible .. can’t do that so well on cardboard without plenty of burning.
      7. The most important part is clicking the upper right “Properties” button and selecting the M2 board.. it had the -B selected. This was my issue. Besides that it’s pretty easy to figure out.
      8. After your first cut or really anything to toolbar goes away but you’ll find it down in the task menu, you can use it from there just fine.
      9. The only thing I’m confused on is the power. The tube is 40 watts, the power supply is 15kV.. it says up to 22mA.. doesn’t that equal >300 watts? Must be the different between input and output power? 6mA will get you through thin cardboard… it’s the recommended test current. I kind of like the manual current control.. don’t know if I’ll change that.
      10. DONT FORGET TO HOOK UP WATER. I really will need to get a flow switch. I see myself forgetting this and destroying the tube. The FS laser I used had a safety switch… they look cheap online.

 

 

Laser Lasers

YACC40WL – Cheap lasers don’t seem THAT bad.

Yet Another Cheap Chinese 40W Laser.

Okay, 366$.. how could I NOT buy this laser.. I tried to convince myself out of it… they’re in LA, it showed up in 3 days.

I had zero expectations of using the thing as-is. I got spoiled by the Full Spectrum we have in the makerspace; it’s not as fancy as an epilog but you using the print driver you can easily, in plain English, adjust power, speed, number of passes.. the vertical laser alignment.. all things I  rely on. This thing seems to require CoralDraw, launched by some wrapper of a program that adds a menu bar. The program is a plug in of sorts called  LaserDRW but it shows up as CoralLASER. I took an import of an SVG and ran a test run… it worked fine. The laser alignment took about 30 minutes.. really unpacking and all the Styrofoam all over was the only annoying part.

I ran some test fires .. everything works. If I didn’t know better I’d just leave this alone and use it as-is. Its no $3,500  Gen 5 Hobby 20×12.. but not bad. I can’t believe they can ship that much weight for $366. I think if you want an ultra cheap laser and you watch enough youtube videos this thing is a decent purchase. I am glad I had used our laser in the makerspace a couple dozen times with some obvious software; that experience gave me a lot more insight into what I should be looking for.

What will I do?! Well I bought it because I had some recent success with building X axis stepper drives… a couple hundred dollars and I think I can build a decent x-y table. I think I could probably make this into a 800mmx500mm table with easily removable sides and a bench of sorts so that I can etch long items in segments. Obviously I’d have some access control and this is clearly not safe to have open sides .. but I think with precautions I’d be fine…   will I finish this? I hope.. aren’t there already like 2000+ unfinished 40W build blogs out there?

Edit: Link to the eBay auction http://www.ebay.com/itm/-/141690337410?roken=cUgayN&soutkn=EWCTN4

 

 

PIC

Get ready for MPLAB Express, throw away your Arduino

I credit the maker movement with bringing electronics back from the crusty old and lonely electronics hobby back into the main stream. The Arduino is the micro of choice for this army of makers and I conceded it made sense… you install the IDE, plugged in your board into the USB port and a couple clicks later and you have an LED blinking.. the most exciting blinking LED you’d ever seen in most cases. I stuck with the PIC micros because I didn’t see any need to put back on the training wheels.

I got invited to a conference call earlier this week as they rolled out MPLAB Express. I almost passed the email up as spam, I’m glad I didn’t… a quick half hour later and I was in shock. Microchip is now relevant in the hobbyist realm.. They just leapfrogged over Arduino in usability for the beginner. They just released Microchip MPLAB Express a new, free, online cloud-IDE. Write your code (or pick a sample), press the compile button and the .hex file downloads.. DRAG AND DROP the .hex file on to the dev board. … the dev board looks like a plain flash drive… just drag and drop and the code is automatically programmed to the device… DRAG AND DROP.. brilliant.

 

Express Evaluation Board

I received my board today, they’re not in production quite yet but will be shortly. The board has a small programmer on board, removing your need for a PICKit programmer. The programmer is a 18LF15K50 … the onboard application device is a brand new 16F18855. The board comes with a break out of all pins and the MikroBUS standard for modules. Mikroelektronika has a ton of little add-on boards and you can certainly make your own. I suspect this board will cost about 15$ or so.. ? We will have to see when they come out.

So the details?

The online application allows you to bypass the need for MPLAB IDE and XC8 compiler installations on your local PC in trade for using a web brower on your favorite device. They mentioned it works on most common browser platforms on Windows, Mac, and Linux. They said it even works on android and iOS, … I’ll check it out on the android later.

I logged on before the webex to check out the environment found at http://mplabexpress.microchip.com and was initially concerned they missed the boat by not including MCC. Well it turns out MCC is available when you create a free account and logon. (Phew! Near miss Microchip!) MCC is kind of like a cheat-sheet app for settings like micro clock frequency, output setup, etc..

What I like: They’ll give you a comparison of premium optimization next to the standard free compiled version (XC8)! They also will allow you to use the premium optimization by subscription that is easy to start/stop. The price is $30/month… so if you just happened to need to squeeze your code into something you can pick up the premium optimization for a month and take it easy on Starbucks for the week and you’re a wash. I also really like that MCC is online and the programming is drag and drop on the dev board..

I have seen two people complain about how the premium XC8 compiler is not included but I have had no issues with the free version, and when you’re a hobbyist of low volume user you can usually just use the next chip size up with more flash for a dollar… I don’t have a problem paying for premium services if I want them. If you’re really hell bent on a chip spend the $30 bucks for a single month of premium use…

The dev board, I think it’s a $10-15 board but I’m get mine for free so I’m not certain.. the PIC16F18855 sits on the board and uses drag and drop programming. The device looks like a flash drive.. just drop your hex code (downloaded from the online site when compiling) and it’s programmed! Brilliant.. easier than the Arduino. Oh yeah, they even have code samples that are tried and tested ready to go with a wiki if you want to do some bathroom reading.

I plan on putting on an introduction course in my makerspace once I get my dev board… I’ll probably pick up a handful of the dev boards as well so I can give them out. If you’re local let’s meetup and try it out.

 

1-wire 18F14K22 Accelerometer C i2c LEDs Microcontrollers PIC RS-232

WS2812 RGB and BNO055 IMU PIC Projects

This weekend I spent my Friday afternoon and Saturday at the NW Hobby Expo; talk about an intense desire to get another hobby.

RC Plane NW Hobby Expo

Oh wait… oops; don’t tell me wife 😉 Should be here tomorrow. A little small guy to get me started.

hk_order201602

I was out helping a friend sell 3D printers and interest people into joining our Makerspace.. mission success? I don’t know we’ll see at the next open house.

The makerspace has kept me busy every moment I haven’t been spending with my little man.. thankfully my makerspace activities have been more to my desires.. I developed a little code to run WS2812 LED drivers for a PIC… why we used a PIC (my fav) I’m unsure.. these maker-folks are all Arduino… I borrow a board and took a look. It’s cute.. micros with training wheels. Here is some basic code to generate colors.. maybe it’ll cut your dev time down on a real project.
RGB WS2812 PIC


/*
 * File:   main.c
 * Author: Charles M Ihler
 * Contact at: http://iradan.com
 *
 * Created on Janurary 1, 2015
 *
 * Target Device:
 * 18F14K22 
 *
 * Project: RGB Resistor Clock
 *
 
 * Version:
 * 0.1  Configuration, with reset test
 * 0.2  Send a single color to 1 neopixel (WS2811/WS2812)
 *
 */
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000 //16Mhz FRC internal osc
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/16000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/16000.0)))
#endif

#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))

#include 
#include 
#include 
#include 


//config bits
#pragma config FOSC=IRC, WDTEN=OFF, PWRTEN=OFF, MCLRE=ON, CP0=OFF, CP1=OFF, BOREN=ON
#pragma config STVREN=ON, LVP=OFF, HFOFST=OFF, IESO=OFF, FCMEN=OFF

#define _XTAL_FREQ 64000000 //defined for delay

/*
 * Variables
 */

    int     device_present;             // 1 = 1-wire device on 1-wire bus
    int     i, x, y, temp, an4_value;               //
    long int    decm;
    int     itxdata, txdata;            //int RS232 tx data
    char    rxbuff[10], z[1], buf[4];                 //buffer for T-sense 1-wire device
    float    temperature, f, d;
    volatile unsigned int uart_data;    // use 'volatile' qualifer as this is changed in ISR

/*
 *  Functions
 */

    void interrupt ISR() {

    if (PIR1bits.RCIF)          // see if interrupt caused by incoming data .. unused currently
    {
        uart_data = RCREG;     // read the incoming data
        PIR1bits.RCIF = 0;      // clear interrupt flag
                                //
    }
    // I left this timer interrupt if I needed it later. This is unused.
    if (PIR1bits.TMR1IF)
    {
        //T1CONbits.TMR1ON = 0;
        
        PIR1bits.TMR1IF = 0;
        //T1CONbits.TMR1ON = 1;

    }
}


     void __delay_10ms(unsigned char n)     //__delay functions built-in can't be used for much at this speed... so!
 {
     while (n-- != 0) {
         __delay_ms(10);
     }
 }


void uart_send (unsigned int mydata_byte) {      //bytes

    while(!TXSTAbits.TRMT);    // make sure buffer full bit is high before transmitting
    TXREG = mydata_byte;       // transmit data
}

void write_uart(const char *txt)                //strings
{
                                //this send a string to the TX buffer
                                //one character at a time
       while(*txt)
       uart_send(*txt++);
}

//This code if from Microchip but is unused currently.
void uart_send_hex_ascii(unsigned char display_data)
{

	//unsigned char temp;
	//temp = ((display_data & 0xF0)>>4);
	//if (temp <= 0x09)
	//	Putchar(temp+'0');
	//else
	//	Putchar(temp+'0'+0x07);
        //
	//temp = display_data & 0x0F;
	//if (temp <= 0x09)
	//	Putchar(temp+'0');
	//else
	//	Putchar(temp+'0'+0x07);

	//Putchar('\r');
	//Putchar('\n');
}

void serial_init(void)
{

    // calculate values of SPBRGL and SPBRGH based on the desired baud rate
    //
    // For 8 bit Async mode with BRGH=0: Desired Baud rate = Fosc/64([SPBRGH:SPBRGL]+1)
    // For 8 bit Async mode with BRGH=1: Desired Baud rate = Fosc/16([SPBRGH:SPBRGL]+1)



    TXSTAbits.BRGH=1;       // select low speed Baud Rate (see baud rate calcs below)
    TXSTAbits.TX9=0;        // select 8 data bits
    TXSTAbits.TXEN=1;     // enable transmit
    BAUDCONbits.BRG16=0;

    RCSTAbits.SPEN=1;       // serial port is enabled
    RCSTAbits.RX9=0;        // select 8 data bits
    RCSTAbits.CREN=1;       // receive enabled


    SPBRG=25;               //38,400bps-ish
                            //BRG16=0, 7=31.25k, 25=9.615k

    PIR1bits.RCIF=0;        // make sure receive interrupt flag is clear
    PIE1bits.RCIE=1;        // enable UART Receive interrupt


         __delay_ms(10);        // give time for voltage levels on board to settle

}

void send_low(void){
    LATCbits.LATC0 = 1;
    _delay(5);
    LATCbits.LATC0 = 0;
    _delay(11);
}

void send_high(void){
    LATCbits.LATC0 = 1;
    _delay(11);
    LATCbits.LATC0 = 0;
    _delay(8);
}


void init_io(void) {
    ANSEL = 0x00;         
    ANSELH = 0x00;

    TRISAbits.TRISA0 = 1; // PGD
    TRISAbits.TRISA1 = 1; // PGC
    TRISAbits.TRISA2 = 0; // output
    TRISAbits.TRISA4 = 1; // OSC
    TRISAbits.TRISA5 = 1; // OSC



    TRISBbits.TRISB4 = 0; // output
    TRISBbits.TRISB5 = 1; // input (RX UART)
    TRISBbits.TRISB6 = 0; // output
    TRISBbits.TRISB7 = 0; // output (TX UART)

    LATC = 0x00;

    TRISCbits.TRISC0 = 0; // WG2812 Output
    TRISCbits.TRISC1 = 1; // 
    TRISCbits.TRISC2 = 0; // 
    TRISCbits.TRISC3 = 0; // 
    TRISCbits.TRISC4 = 0; // 
    TRISCbits.TRISC5 = 0; // output
    TRISCbits.TRISC6 = 1; // input
    TRISCbits.TRISC7 = 1; // input

}

void send_black (void) {
        send_low(); //G1
        send_low(); //G2
        send_low(); //G3
        send_low(); //G4
        send_low(); //G5
        send_low(); //G6
        send_low(); //G7
        send_low(); //G8
        
        send_low(); //R1
        send_low(); //R2
        send_low(); //R3
        send_low(); //R4
        send_low(); //R5
        send_low(); //R6
        send_low(); //R7
        send_low(); //R8
        
        send_low(); //B1 00000 0000
        send_low(); //B2
        send_low(); //B3
        send_low(); //B4
        send_low(); //B5
        send_low(); //B6
        send_low(); //B7
        send_low(); //B8
}

void send_brown (void) {
        send_low(); //G1 64
        send_low(); //G2 
        send_high(); //G3 
        send_low(); //G4 
        send_low(); //G5 
        send_low(); //G6 
        send_low(); //G7 
        send_low(); //G8 
        
        send_low(); //R1 128
        send_high(); //R2 0
        send_low(); //R3 1
        send_low(); //R4 0
        send_low(); //R5 0
        send_low(); //R6 1
        send_low(); //R7 0
        send_low(); //R8 1      
  
        send_low(); //B1 0
        send_low(); //B2
        send_low(); //B3
        send_low(); //B4
        send_low(); //B5
        send_low(); //B6
        send_low(); //B7
        send_low(); //B8
}

void send_orange (void) {
        send_high(); //G1 165 / 1010 0101
        send_low(); //G2 
        send_high(); //G3 
        send_low(); //G4 
        send_low(); //G5 
        send_high(); //G6 
        send_low(); //G7 
        send_high(); //G8 
        
        send_high(); //R1 1111 1111
        send_high(); //R2 
        send_high(); //R3 
        send_high(); //R4 
        send_high(); //R5 
        send_high(); //R6 
        send_high(); //R7 
        send_high(); //R8       
  
        send_low(); //B1 00000 0000
        send_low(); //B2
        send_low(); //B3
        send_low(); //B4
        send_low(); //B5
        send_low(); //B6
        send_low(); //B7
        send_low(); //B8
}


void send_yellow (void) {
        send_high(); //G1 255 / 1111 1111
        send_high(); //G2 
        send_high(); //G3 
        send_high(); //G4 
        send_high(); //G5 
        send_high(); //G6 
        send_high(); //G7 
        send_high(); //G8 
        
        send_high(); //R1 1111 1111
        send_high(); //R2 
        send_high(); //R3 
        send_high(); //R4 
        send_high(); //R5 
        send_high(); //R6 
        send_high(); //R7 
        send_high(); //R8       
  
        send_low(); //B1 00000 0000
        send_low(); //B2
        send_low(); //B3
        send_low(); //B4
        send_low(); //B5
        send_low(); //B6
        send_low(); //B7
        send_low(); //B8
}

void send_blue (void) {
        send_low(); //G1
        send_low(); //G2
        send_low(); //G3
        send_low(); //G4
        send_low(); //G5
        send_low(); //G6
        send_low(); //G7
        send_low(); //G8
        
        send_low(); //R1
        send_low(); //R2
        send_low(); //R3
        send_low(); //R4
        send_low(); //R5
        send_low(); //R6
        send_low(); //R7
        send_low(); //R8        
  
        send_high(); //B1
        send_high(); //B2
        send_high(); //B3
        send_high(); //B4
        send_high(); //B5
        send_high(); //B6
        send_high(); //B7
        send_high(); //B8
}

void send_green (void) {
        send_high(); //G1
        send_high(); //G2
        send_high(); //G3
        send_high(); //G4
        send_high(); //G5
        send_high(); //G6
        send_high(); //G7
        send_high(); //G8
        
        send_low(); //R1
        send_low(); //R2
        send_low(); //R3
        send_low(); //R4
        send_low(); //R5
        send_low(); //R6
        send_low(); //R7
        send_low(); //R8        
  
        send_low(); //B1
        send_low(); //B2
        send_low(); //B3
        send_low(); //B4
        send_low(); //B5
        send_low(); //B6
        send_low(); //B7
        send_low(); //B8
}

void send_grey (void) {
        send_low(); //G1
        send_low(); //G2
        send_high(); //G3
        send_low(); //G4
        send_low(); //G5
        send_low(); //G6
        send_low(); //G7
        send_low(); //G8
        
        send_low(); //R1
        send_low(); //R2
        send_high(); //R3
        send_low(); //R4
        send_low(); //R5
        send_low(); //R6
        send_low(); //R7
        send_low(); //R8        
  
        send_low(); //B1
        send_low(); //B2
        send_high(); //B3
        send_low(); //B4
        send_low(); //B5
        send_low(); //B6
        send_low(); //B7
        send_low(); //B8
}

void send_violet (void) {
        send_low(); //G1
        send_low(); //G2
        send_low(); //G3
        send_low(); //G4
        send_low(); //G5
        send_low(); //G6
        send_low(); //G7
        send_low(); //G8
        
        send_high(); //R1
        send_high(); //R2
        send_high(); //R3
        send_high(); //R4
        send_high(); //R5
        send_high(); //R6
        send_high(); //R7
        send_high(); //R8        
  
        send_high(); //B1
        send_high(); //B2
        send_high(); //B3
        send_high(); //B4
        send_high(); //B5
        send_high(); //B6
        send_high(); //B7
        send_high(); //B8
}

void send_red (void) {
        send_low(); //G1
        send_low(); //G2
        send_low(); //G3
        send_low(); //G4
        send_low(); //G5
        send_low(); //G6
        send_low(); //G7
        send_low(); //G8
        
        send_high(); //R1
        send_high(); //R2
        send_high(); //R3
        send_high(); //R4
        send_high(); //R5
        send_high(); //R6
        send_high(); //R7
        send_high(); //R8        
  
        send_low(); //B1
        send_low(); //B2
        send_low(); //B3
        send_low(); //B4
        send_low(); //B5
        send_low(); //B6
        send_low(); //B7
        send_low(); //B8
}

void send_white (void) {
        send_high(); //G1 255 / 1111 1111
        send_high(); //G2 
        send_high(); //G3 
        send_high(); //G4 
        send_high(); //G5 
        send_high(); //G6 
        send_high(); //G7 
        send_high(); //G8 
        
        send_high(); //R1 1111 1111
        send_high(); //R2 
        send_high(); //R3 
        send_high(); //R4 
        send_high(); //R5 
        send_high(); //R6 
        send_high(); //R7 
        send_high(); //R8       
  
        send_high(); //B1
        send_high(); //B2
        send_high(); //B3
        send_high(); //B4
        send_high(); //B5
        send_high(); //B6
        send_high(); //B7
        send_high(); //B8
}


int main(void) {

    init_io();

    // set up oscillator control register, using internal OSC at 16MHz.
    OSCCONbits.IRCF = 0x07; //set OSCCON IRCF bits to select OSC frequency 16MHz
    OSCCONbits.SCS = 0x00; //set the SCS bits to select internal oscillator block
    OSCTUNEbits.PLLEN = 0x01;   //x4 PLL
    //RCONbits.IPEN = 0;          //disable priority levels

    INTCONbits.PEIE = 1;        // Enable peripheral interrupt
    INTCONbits.GIE = 1;         // enable global interrupt

    temp = 0x10000000;

    while (1) {
        //RGB high bit first
        //if (CHECK_BIT(temp, 0)) {
        //send_high(); //G1    
        //} else {
        //send_low(); //G1    
        //}
        
        send_brown();
        send_orange();
        send_yellow();
        
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);        
        
        send_black();    //1st LED
        send_grey();   //2nd LED
        send_white();     //3rd LED

        
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);    
        
        //send_green();
        //send_violet();
        //send_grey();
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10);
        __delay_ms(10); 
        __delay_us(100);

    }
    return (EXIT_SUCCESS);
}

It’s very very dirty and there is some un-used stuff… but it was a quick hack based on old code and I didn’t optimize the delays at all.
… This is work in progress for a resistor color code clock. I’ll obviously need to switch to a crystal, etc.

I also threw together some basic test code for the 9DOF BNO055 IMU. I bought one just for kicks in case I want to add it to my SRS Pop Can Challenge competition robot. I volunteered for the job left over on our makerspace robot group project… because power systems are a bit of a snooze, and I’m pretty much done, I decided to make my own. It won’t win (because I’m not going for all the points) but it’ll be another robot on the field. Here is some cBode to get you started if you’re interested… I used the Adafruit BOB.. pretty cool and they broke out just enough stuff it seems. I tried it with the UART interface first for kicks.. but then switched to I2C.


/*
 * File:   main.c
 * Author: Charles M Ihler
 * Contact at: http://iradan.com
 *
 * Created on February 8, 2014, 11:39 AM
 *
 * Target Device:
 * 18F14K22 on Tautic 20 pin dev board
 *
 * Project: IMU for PCC
 *
 *
 * Version:
 * 0.1  IO Confoiguration RS232/TX/I2C
 * 0.2  Test BNO055 by UART
 * 0.3  Dump UART interface and get cal status via I2C and send to UART 
 *
 */
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 16000000 //4Mhz FRC internal osc
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/16000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/16000.0)))
#endif

#include 
#include 
#include 
#include 


//config bits
#pragma config FOSC=IRC, WDTEN=OFF, PWRTEN=OFF, MCLRE=ON, CP0=OFF, CP1=OFF, BOREN=ON
#pragma config STVREN=ON, LVP=OFF, HFOFST=OFF, IESO=OFF, FCMEN=OFF

/*
 * Variables
 */

#define r_device_address  0x51 // BNO055 Default Address
#define w_device_address  0x50 // BNO055 Default Address

    unsigned int ACK_bit;
    int i;
    unsigned char byte, tempbyte1, tempbyte2;

    int     w0,w1,w2,w3,w4;     //confirguration words
    int     present;              //device present
    //int     itxdata;            //int RS232 tx data
    //char    buf[10];            //buff for iota
    volatile unsigned int uart_data;    // use 'volatile' qualifer as this is changed in ISR

/*
 *  Functions
 */

    void interrupt ISR() {

    if (PIR1bits.RCIF)          // see if interrupt caused by incoming data
    {
        uart_data = RCREG;     // read the incoming data
        if (uart_data == 0xBB)
        {
            LATAbits.LA0 = 1;
            present = 1;
        }
        PIR1bits.RCIF = 0;      // clear interrupt flag
                                //
    }
    if (INTCONbits.T0IF)
    {
        //LATAbits.LATA0 = 1;
        INTCONbits.T0IF = 0;
    }

}

void __delay_10ms(unsigned char n)     //__delay functions built-in can't be used for much at this speed... so!
 {
     while (n-- != 0) {
         __delay_ms(10);
     }
 }
     
void uart_tx(unsigned int mydata_byte) {
    while(!TXSTAbits.TRMT);    // make sure buffer full bit is high before transmitting
    TXREG = mydata_byte;       // transmit data
}

void write_uart(const char *txt){
    while(*txt != 0) uart_tx(*txt++);     //this send a string to the TX buffer
                                            //one character at a time
}

void serial_init(void)
{

    // calculate values of SPBRGL and SPBRGH based on the desired baud rate
    //
    // For 8 bit Async mode with BRGH=0: Desired Baud rate = Fosc/64([SPBRGH:SPBRGL]+1)
    // For 8 bit Async mode with BRGH=1: Desired Baud rate = Fosc/16([SPBRGH:SPBRGL]+1)



    TXSTAbits.BRGH=1;       // 
    TXSTAbits.TX9=0;        // select 8 data bits
    TXSTAbits.TXEN = 1;     // enable transmit


    RCSTAbits.SPEN=1;       // serial port is enabled
    RCSTAbits.RX9=0;        // select 8 data bits
    RCSTAbits.CREN=1;       // receive enabled

    SPBRG=103;               //

    PIR1bits.RCIF=0;        // make sure receive interrupt flag is clear
    PIE1bits.RCIE=1;        // enable UART Receive interrupt
    INTCONbits.PEIE = 1;    // Enable peripheral interrupt
    INTCONbits.GIE = 1;     // enable global interrupt
    INTCONbits.T0IE = 0;

         __delay_10ms(5);        // give time for voltage levels on board to settle
}


void init_io(void) {
    TRISAbits.TRISA0 = 0; // output
    TRISAbits.TRISA1 = 1; // input
    TRISAbits.TRISA2 = 1; // 
    TRISAbits.TRISA4 = 1; // 
    TRISAbits.TRISA5 = 1; // 
    
    ANSEL = 0x00;         // no A/D
    ANSELH = 0x00;

    TRISBbits.TRISB4 = 1; // RB4 I2C SDA, has to be set as an input
    TRISBbits.TRISB5 = 1; // RB5 = nc
    TRISBbits.TRISB6 = 1; // RB6 I2C SCLK, has to be set as an input
    TRISBbits.TRISB7 = 0; // RS232 TX

    WPUBbits.WPUB4 = 0x01;        //PORT B WEAK PULL UPS
    WPUBbits.WPUB6 = 0x01;
    
    TRISCbits.TRISC0 = 1; // 
    TRISCbits.TRISC1 = 1; // input
    TRISCbits.TRISC2 = 1; // 
    TRISCbits.TRISC3 = 0; // 
    TRISCbits.TRISC4 = 0; // 
    TRISCbits.TRISC5 = 0; // 
    TRISCbits.TRISC6 = 1; // input
    TRISCbits.TRISC7 = 1; // input

    __delay_10ms(10);   //let voltage settle
    
    //write_uart("RESET\n");         // transmit some data

}

void I2C_ACK(void)
{
   PIR1bits.SSPIF=0;          // clear SSP interrupt bit
   SSPCON2bits.ACKDT=0;        // clear the Acknowledge Data Bit - this means we are sending an Acknowledge or 'ACK'
   SSPCON2bits.ACKEN=1;        // set the ACK enable bit to initiate transmission of the ACK bit to the serial eeprom
   while(!PIR1bits.SSPIF);    // Wait for interrupt flag to go high indicating transmission is complete
}

void Send_I2C_Data(unsigned int databyte)
{
    PIR1bits.SSPIF=0;          // clear SSP interrupt bit
    SSPBUF = databyte;              // send databyte
    while(!PIR1bits.SSPIF);    // Wait for interrupt flag to go high indicating transmission is complete
}

unsigned char RX_I2C_Data (void)
{
    RCEN = 1;               // 
    while( RCEN ) continue;
    while( !BF ) continue;
    byte = SSPBUF;
   return byte;
}

void I2C_Control_Write(void)
{
    PIR1bits.SSPIF=0;          // clear SSP interrupt bit
    SSPBUF = w_device_address;             // send the control byte (90 TCN75, EF BMP085)
    while(!PIR1bits.SSPIF)     // Wait for interrupt flag to go high indicating transmission is complete
        {
        i = 1;
          // place to add a breakpoint if needed
        }
    PIR1bits.SSPIF=0;

}

void I2C_Control_Read(void)
{
    PIR1bits.SSPIF=0;          // clear SSP interrupt bit
    SSPBUF = r_device_address;   // send the control byte (90 TCN75, EF BMP085)
    while(!PIR1bits.SSPIF)     // Wait for interrupt flag to go high indicating transmission is complete
        {
        i = 1;
          // place to add a breakpoint if needed
        }
    PIR1bits.SSPIF=0;
   }


void I2C_Start_Bit(void)
{
    PIR1bits.SSPIF=0;          // clear SSP interrupt bit
    SSPCON2bits.SEN=1;          // send start bit
    while(!PIR1bits.SSPIF)    // Wait for the SSPIF bit to go back high before we load the data buffer
        {
        i = 1;
        }
    PIR1bits.SSPIF=0;
}

void I2C_check_idle()
{
    unsigned char byte1; // R/W status: Is a transfer in progress?
    unsigned char byte2; // Lower 5 bits: Acknowledge Sequence, Receive, STOP, Repeated START, START

    do
    {
        byte1 = SSPSTAT & 0x04;
        byte2 = SSPCON2 & 0x1F;
    } while( byte1 | byte2 );
}
/*
 * Send the repeated start message and wait repeated start to finish.
 */
void I2C_restart()
{
    I2C_check_idle();
    RSEN = 1; // Reinitiate start
    while( RSEN ) continue;
}

void I2C_Stop_Bit(void)
{
    PIR1bits.SSPIF=0;          // clear SSP interrupt bit
    SSPCON2bits.PEN=1;          // send stop bit
    while(!PIR1bits.SSPIF)
    {
        i = 1;
        // Wait for interrupt flag to go high indicating transmission is complete
    }
}

void I2C_NAK(void)
{
    PIR1bits.SSPIF=0;           // clear SSP interrupt bit
    SSPCON2bits.ACKDT=1;        // set the Acknowledge Data Bit- this means we are sending a No-Ack or 'NAK'
    SSPCON2bits.ACKEN=1;        // set the ACK enable bit to initiate transmission of the ACK bit to the serial eeprom
    while(!PIR1bits.SSPIF)     // Wait for interrupt flag to go high indicating transmission is complete
    {
        i = 1;
    }
}

void read_imu_status(void){
    
    I2C_Start_Bit();                    // send start bit
    I2C_Control_Write();                // send control byte with read set
    Send_I2C_Data(0x00);                // register

    I2C_restart();                      // restart

    I2C_Control_Read();
    RX_I2C_Data();                      // read high
    tempbyte1=byte;
//    I2C_ACK();                          // ACK
//    RX_I2C_Data();                      // read low
//    tempbyte2=byte;
    I2C_NAK();                          // NAK
    //I2C_restart();
    I2C_Stop_Bit();                     // Send Stop Bit

    uart_tx(tempbyte1);               //send data off raw by UART

}

void read_imu_cal_status(void){
    
    I2C_Start_Bit();                    // send start bit
    I2C_Control_Write();                // send control byte with read set
    Send_I2C_Data(0x35);                // register

    I2C_restart();                      // restart

    I2C_Control_Read();
    RX_I2C_Data();                      // read high
    tempbyte1=byte;
//    I2C_ACK();                          // ACK
//    RX_I2C_Data();                      // read low
//    tempbyte2=byte;
    I2C_NAK();                          // NAK
    //I2C_restart();
    I2C_Stop_Bit();                     // Send Stop Bit

    uart_tx(tempbyte1);               //send data off raw by UART

}

void write_imu_9DOF(void)
{

    I2C_Start_Bit();                    // send start bit
    I2C_Control_Write();                // send control byte
    Send_I2C_Data(0x3D);                // address
    Send_I2C_Data(0x1C);                // enable 9dof
    I2C_Stop_Bit();

}

void i2c_muck(void)
{

    I2C_Start_Bit();                     // send start bit
    I2C_Control_Write();                  // send control byte with read set

    //if (!SSP1CON2bits.ACKSTAT)
    //LATCbits.LATC1 = 0;                   //device /ACked?

    Send_I2C_Data(0x01);                //pointer
    Send_I2C_Data(0xE1);                //1 shot, 12bit res
    I2C_Stop_Bit();

    __delay_10ms(50);                     //wait for conversion

    I2C_Start_Bit();                     // send start bit
    I2C_Control_Write();                  // send control byte with read set

    //    if (!SSP1CON2bits.ACKSTAT)
//    LATCbits.LATC1 = 0;

    Send_I2C_Data(0x00);                //pointer

    I2C_restart();                      //restart
    I2C_Control_Read();
    RX_I2C_Data();                      //read high
    tempbyte1=byte;
    I2C_ACK();                          //ACK
    RX_I2C_Data();                      //read low
    tempbyte2=byte;
    I2C_NAK();                          //NAK
    //I2C_restart();
    I2C_Stop_Bit();                     // Send Stop Bit

    uart_tx(tempbyte1);               //send data off raw by UART
    uart_tx(tempbyte2);
}


int main(void) {

    // set up oscillator control register, using internal OSC at 16MHz.
    OSCCONbits.IRCF = 0x07; //set OSCCON IRCF bits to select OSC frequency 16MHz
    OSCCONbits.SCS = 0x02; //set the SCS bits to select internal oscillator block
    //OSCTUNEbits.PLLEN = 0x01;   // PLL ENABLE FOSC -> 64MHz
    //OSCTUNEbits.TUN = 0x63;     ///trim up that frequency to get closed to 115200

    init_io();
    serial_init();
  
    SSPCON1bits.SSPM=0x08;       // I2C Master mode, clock = Fosc/(4 * (SSPADD+1))
    SSPCON1bits.SSPEN=1;         // enable MSSP port
    SSPADD = 0x09;             // 100KHz

    // ***********************************************************************************
    __delay_10ms(100);

    
    //init -- check and wait for IMU
    
    // test
    tempbyte1 = 0xFF;
    
    uart_tx(tempbyte1);               //send data off raw by UART
    uart_tx(0xAA);
    
    __delay_10ms(100);
    
    read_imu_status();    
    //set IMU for 9DOF
    __delay_10ms(10);
    
    
    write_imu_9DOF();
    
    //     UART method
    //     uart_tx(0xAA);                   //Start
    //     uart_tx(0x00);                   //read
    //     uart_tx(0x3D);                   //address 
    //     uart_tx(0x01);                   //length 
    //     uart_tx(0x1C);                   //data 9DOF

    __delay_10ms(50);

    while (1) {
         __delay_10ms(10);                   //delay for debugging

        LATAbits.LA0 = 0;           //good rx flag off
        //LATCbits.LATC3 = 0;
        //__delay_ms(149);
        //LATCbits.LATC3 = 1;     //debugging
        read_imu_cal_status();
  
        LATAbits.LA0 = 1;           //good rx flag on
         __delay_10ms(150);                   //delay for debugging
        
     }                                      //... wash, rinse, repeat
    return;
}



So yeah, again also sloppy but maybe you can use some of it. Price is right anyways.

Okay well maybe you might have notices a TINY gap in posting… it seems I greatly underestimated the amount of time a baby consumes in your life. I have a 9 month old son now.. he is running around trying to chew on USB cables (his favorite)… he’s just now realizing a bit of independence and with a recent purchase of a nice Lenovo Yoga 900 to replace my couple month old dead Sony Vaio I now can develop from the couch.. though I have a porta-crib in the workshop 🙂

DIY Robotics

MiniSumo Ring

Before I continue on you might have noted a little bit of an absence in my blogging. My wife delivered my first son two weeks ago; a beautiful little man, 8lbs 9 oz, 21.25in. Missing a little sleep isn’t helping but I think we have finally gotten into a schedule that is nearly do-able!

So what have I been working on?! I’ve been dedicating what free time I do to the Snohomish County Makers Group. It’s been a blast but it’s surprising how much work it is to start one up; that’s no bother though because it’s really exciting to see where this will go.

A good friend of mine, also a member of the group, mentioned he was interested in a Sumo Robot competition; or maybe it was me? Well it doesn’t matter, it’s on!

I spend a couple of hours this weekend putting together the ring. There are a couple different standards but the SRS seems to have a pretty good set. I took their rules and modified the ring size and platform specifications based on our desire to use a low-cost platform so it was affordable for anyone to enter.

I used the old nail and pencil trick to draw the circle and a steady hand to saw it out out of a 4′ square piece of  3/4″ plywood..

Ring getting patched

There were some minor imperfections that I used some Elmer’s wood filler on and then sanded flat.

I threw on a 10cm border and painted it glossy white for a nice reflection for edge sensors..

MiniSumo Ring

Next step is pulling the old platform off my little robot and starting over…

Stay tuned!

DIY Electronics Microcontrollers PIC Robotics

The Sumo Roomba is back on the bench

I had to tear my Variac apart today because the wiper was missing on bits..  I gave it a solid cleaning got rid of some rust on the case. I used alcohol to do the cleaning.. worked out great. I don’t use my Variac as much as I used to.. in fact I nearly got out of the hobby over my very first. When I was 14 I understood what transformers were and I had been playing with very high voltage (neon transformers)…  I wanted more voltage so I thought I might test the insulation a bit. Seeing as I didn’t have any good way to get more voltage I thought I’d just flip my primary and secondary around running my secondary in the 80~110 volt range. Well.. that doesn’t work out so well. My variac was on it’s side and at about the 2 o’clock position.; it blew out every winding from 2 o’clock down to 6.. I had issues plugging things in for a while after that 😀

I eventually got over that out of necessity. I used/use variacs for powering up old electronics… it kind of works the old caps in before you hit them hard… filaments as well. Today I was using mine to lower the input to a linear power supply to find the approximate drop out voltage of a piece of equipment; that was in interruption of what I was really doing in my shop.

I pulled my Roomba off the wall. It’s an older 400 series I got for dirt cheap on eBay. A friend of mine at work challenged me to a Roomba Sumo contest; no winner… I think he is still working on his 🙂  My first, current, version is based on two PICs, a 16F628A and a 18F2331; both written in assembly. Well it’s okay.. but I think I can do better. I did the PCB in deadbug… ASM was okay but it takes much longer to develop and making any code remotely tricky is a chore. So this time I think I’ll develop a custom PCB and write it all in C. This new makerspace I’m co-founding looks promising so maybe I’ll sucker a couple of people into joining in the fun.

 

Roomba On the Bench

 

 

I’m re-accomplishing all my sensors; ditching my hardware-happy comparators and going with all A/D. I also never added in switches for my bumpers.. they were pushbutton microswitches on the only mainboard if I’m not mistaken… I’ll figure something out.

 

Roomba Back?

 

 

 

Electronics

SnoCo Makers Group

In my free time I’ve been watching MacGyver episodes on Netflix. It’s week two and I’m just a few into season 2… not so much free time. On Sunday I had a workshop visitor that I went through a Soldering Workshop I have planned; that’s about all the shop time I’ve had. I’ve been busy working on this Makers group I’ve been building with a partner. I really excited about this and should lead to many new adventures! For now the packages are piling up…

If you’re interested check out the SnoCo Makers Group on Meetup.

Analog Electronics RF Tindie Tools and Test Equipment

Just in! and the start on a VSWR bridge

I’ve been working on little bits over the last week or two, nothing notable but filling up my notebook with plenty of “lessons-learned”. For instance I decided I’m no good as estimating how many uH my home-made inductors are. I purchased a BK Precision 879B LCR meter to confirm that fact. A side-bonus was I went through all my caps and could test my home-brew ESR meter vs. the ESR meter built into the 879B and I now have a fair amount of capacitors that are going to the garbage. No more saving scrapped caps for me. I was working on an oscillator the other day.. well I winged the inductor.. not a wiggle out of the oscillator when finished, that’s what finally made me break down and buy the meter..

A crystal oscillator.. that doesn't oscillate
A crystal oscillator.. that doesn’t oscillate

Today I sat down at the bench and I started working on a project I have had on the board for a while (it’s a surprise); for this piece I made a 50 Ohm VSWR interface; then I threw it into a test jig and checked it out. It actually worked pretty solid. I got some 1 watt SMD resistors off an eBay purchased of some 49.9 ohm 0805 SMD resistors I ordered. The guy just randomly threw in 10 1-watt 49.9 ohm resistors… nice guy. I tested it up to 500MHz but after that I had a bit of noise measuring reverse power.. that’s okay though for me. Interestingly I found with my SA I have a pretty solid local noise source at 90.9, some local station I’m sure.  If you’re interested in making your own check out this guy’s website. He has a basic schematic of a bridge that is functionally equivalent to mine it seems. (a bridge with 3 resistors.. not a brain buster).

 

A little home made VSWR bridge for an upcoming project..
A little home made VSWR bridge for an upcoming project..

So after some success I decided it was time to get to mail. Yesterday I got a packages from the @tymkrs and Jason at AtomSoftTech.

Jason stuffed a box with some goodies I ordered and extras (thanks Jason!) The two most notable items of the bunch is the breadboard PIC buddy and the ESP8266 breakout board. The ESP board was flawless, but after use of BB PIC buddy I have ideas for v2. Now let me make it clear I saw this design before it went to the fab and I missed stuff that seems now obvious.. totally my bad.

Is it functional? Yep.. What would I recommend for changes?

Make the power side a little longer and have the USB jack coming in on the side.. if the PICKit2 is plugged in you can’t use the USB connector. Also while the PIC Kit 2 works okay I think pushing it a 1/2 inch away from the RJ12 jack for the ICD would make the insertion a little more solid. Nice product though.. this is certainly a new breadboard-fav. Jason is selling these for too cheap on Tindie. Get it before he gets smart and raises his price 🙂

The BB PIC Buddy and ESP8266 breakout board
The BB PIC Buddy and ESP8266 breakout board

There are some other items from AST as well but I’ll mention them later on. I had purchased two items from the @tymkrs ; the new Analog Shift Kit and the new SMD LM386 audio amplifier “Amplify Me”. The Amplify Me board works as expected, I checked out the PDIP version of this some time back ago, I’m not going to hunt for the post though, it’s a LM386 audio amp, kind of a no-brainer. I though of one change for future versions of this product that might have been a little more user friendly. It’d be nice if they made the product just a few more tenths of inches wide and brought that PCB 3.5mm jack out away and further back (back in reference to the photo below). I would make the jack so that it was level with a panel if you mounted the potentiometer into a panel. I don’t think it would add too much to board coast but it wold make this much easier to integrate into projects. As it is though, the potentiometer doesn’t have to be soldered into the board (it doesn’t come soldered) so it would be easier enough to work around. I still find it shocking to get a battery included in an order! It’s the little things @tymkrs!

Updated @tymkrs SMD LM386 Amplify Me
Updated @tymkrs SMD LM386 Amplify Me

No time to get to the Analog Shift kit today, I’ll save that for the future.

I have a lot more Analog bits I’m working on in the near future; I hope to get some of them mentioned here.

1-wire 18F14K22 C Electronics Interface Microcontrollers PIC Weather

iButtonLink T-Sense 1-wire sensor (Maxim DS18B20) + PIC 18F14K22

I came across a stash of iButton T-sense 1-wire sensors.. so I grabbed a couple and decided to check out 1-wire.

Maxim makes a 1-wire device called the DS18B20. It’s a 9-12 bit temperature sensor with the possibility of being powered by parasitic power from the data line. This cuts the signal path down to a single DQ line and a return. A company called iButtonLink produces a nice little wrapper around this device called a T-Sense. There are a couple pieces of software out there that will allow you to hook these up to monitoring systems, I don’t have any though. These devices come with a 64-bit address code and can be daisy-chained which makes having many of these devices monitored very nice.

At first I thought, ugh.. lame I have to send, and parse 64-bit codes in a little 8 bit micro.. doesn’t sound like a ton of fun for just fooling around on a day off.. thank fully they have a “Skip ROM” feature/command which works similar to a broadcast but can only be used when you have one device on the bus. If there is one thing left in this project I might consider finishing it’d be to add the addressing in and daisy-chain a few of these.

Most of my research came from Microchip’s Application Note AN1199 though the T-Sense Users Manual also helped out including determining the wiring diagram.

For my circuit I hooked up 5VDC (but later ran it on 3.3V just fine) and the 5VDC return on pins 1 & 2. Then the DQ link and return on pins 4&5. The signaling is interesting as the 1-wire bus needs a weak pull and works with an open collector circuits. The master starts all signaling, writes and reads. The 1’s and 0’s are based on how long the master or slave sinks the DQ line. To accomplish this in the PIC microcontroller I switched the port from an output to a three state input when I needed the port to be in weak-pull up mode (which is also hand when I need to sample the port for a response from a slave). The pull up on the resistor in my circuit is 10Kohm but I’ve seen 4.7KOhm and I’m sure anywhere in the neighborhood is fine. Finally if you do some digging you’ll notice I run this in low speed mode, if I remember correctly the “high speed” mode is 4x faster. I don’t think speed of data transfer is really relevant when you’re waiting for 750ms for a temperature conversation though.

T-sense sensor and 18F14k22 PIC Microcontroller on the breadboard
T-sense sensor and 18F14k22 PIC Microcontroller on the breadboard

I initially started with just determining if there was a 1-wire device on the bus. If you perform a “reset” (master sinks the bus low for 480us then releases to hi-z for 70us and then performed a sample.. any (all) device(s) will sink the line slow to prove their presence…then another 410us of delay before continuing. I got this one first try.. better luck than my first time with I2C! I then wrote the code (including sampling tidbits of Microchip AN1199 code to optimize) to do an actual temperature conversion and request it (by commanding a “read scratch pad”). The device dumps all 9 bytes of it’s registers. On that note I just remembered I should mention I did NOTHING with the CRC byte.. that’s all you if you care.

My temperature conversion code looks like this: (bus control m = master or PIC, s=slave or sensor)

m RESET

s PRESENCE flag

m SKIP ROM (0xCC)

m CONV TEMP (0x44)

m HOLD DQ (Hold line high 750ms for 12bit conversion .. I am guessing we hold it high for the parasitic power supply)

m RESET

s PRESENCE flag

m SKIP ROM (0xCC)

m READ SCRATCHPAD (0xBE)

s 9 Bytes of Data

and that looks like…

1-wire data capture on the logic analyzer
1-wire data capture on the logic analyzer

 

The 12-bit conversion is basically 0.0625 deg C for every bit from 0C, The LSB holds a temperature sign.

The output of my program looks like..

Final Results!
Final Results!

There are tons of details on what a “1” is an what a “0” is, the ROM code (READ ROM, MATCH ROM), changing the configuration to 9bit for 94 ms conversions over 12bit 750ms conversions. This is all stuff you can grab out of the DS18B20 specification sheet or AN1199.

I hope you get some use out of this.. I still have enough of these T-Sense modules.. maybe if someone really wants one I’ll drop it in the mail… or perhaps we can set up a big box of electronics to ship around and I can dump some in there.

Items I used to make this happen:

TAUTIC 20-pin Development Board

Microchip PIC 18F14K22

AST Breadboard Buddy Pro

AST tinyLEDx4

iButtonLink T-Sense

CAT5 breakout board (eBay?)

Microchip PICKit 3

Then miscellaneous tools, test equipment, jumpers and a breadboard.

 

The good stuff (my code):

.. also found here on pastebin: http://pastebin.com/HrLg1GqL

 


/*
 * File:   main.c
 * Author: Charles M Douvier
 * Contact at: http://iradan.com
 *
 * Created on Janurary 1, 2015
 *
 * Target Device:
 * 18F14K22 on Tautic 20 pin dev board
 *
 * Project: Maxim 1-Wire Testing
 *
 * Details of 1-wire protocol using Microchip AN1199
 * Field device http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
 * The 1-Wire Protocol is registered trade mark of Dallas/Maxim semiconductor.
 *
 * Some code was use by the AN1199 App Note Source code; I got stuck looking for a fast way of txing by bit-bang (yes never did this before)
 * The agreement below mentions a license agreement accompaning this software; There was none. I'll note where this software was used if you
 * want to re-write without the Microchip bits.
 * The Microchip licensing as follows:
 *
 *  * FileName:        1wire.c
 * Dependencies:
 * Processor:       PIC18
 * Complier:        MCC18 v3.13
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * Copyright © 2004-2007 Microchip Technology Inc.  All rights reserved.
 *
 * Microchip licenses to you the right to use, copy and distribute Software
 * only when embedded on a Microchip microcontroller or digital signal
 * controller and used with a Microchip radio frequency transceiver, which
 * are integrated into your product or third party product (pursuant to the
 * sublicense terms in the accompanying license agreement).  You may NOT
 * modify or create derivative works of the Software.
 *
 *
 * You should refer to the license agreement accompanying this Software for
 * additional information regarding your rights and obligations.
 *
 * SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
 * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR
 * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED
 * UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF
 * WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR
 * EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT,
 * PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY
 * THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER
 * SIMILAR COSTS.
 *
 *
 *
 * Version:
 * 0.1  Configuration, with reset test
 * 0.2
 *
 */
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 16000000 //4Mhz FRC internal osc
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
#endif

#include 
#include 
#include 
#include 


//config bits
#pragma config FOSC=IRC, WDTEN=OFF, PWRTEN=OFF, MCLRE=ON, CP0=OFF, CP1=OFF, BOREN=ON
#pragma config STVREN=ON, LVP=OFF, HFOFST=OFF, IESO=OFF, FCMEN=OFF

#define _XTAL_FREQ 16000000 //defined for delay

/*
 * Variables
 */

    int     device_present;             // 1 = 1-wire device on 1-wire bus
    int     i, x, y, int_temp, an4_value;               //
    long int    decm;
    int     itxdata, txdata;            //int RS232 tx data
    char    rxbuff[10], z[1], buf[4];                 //buffer for T-sense 1-wire device
    float    temperature, f, d;
    volatile unsigned int uart_data;    // use 'volatile' qualifer as this is changed in ISR

/*
 *  Functions
 */

    void interrupt ISR() {

    if (PIR1bits.RCIF)          // see if interrupt caused by incoming data .. unused currently
    {
        uart_data = RCREG;     // read the incoming data
        PIR1bits.RCIF = 0;      // clear interrupt flag
                                //
    }
    // I left this timer interrupt if I needed it later. This is unused.
    if (PIR1bits.TMR1IF)
    {
        //T1CONbits.TMR1ON = 0;
        PIR1bits.TMR1IF = 0;
        //T1CONbits.TMR1ON = 1;

    }
}


     void __delay_10ms(unsigned char n)     //__delay functions built-in can't be used for much at this speed... so!
 {
     while (n-- != 0) {
         __delay_ms(10);
     }
 }


void uart_send (unsigned int mydata_byte) {      //bytes

    while(!TXSTAbits.TRMT);    // make sure buffer full bit is high before transmitting
    TXREG = mydata_byte;       // transmit data
}

void write_uart(const char *txt)                //strings
{
                                //this send a string to the TX buffer
                                //one character at a time
       while(*txt)
       uart_send(*txt++);
}

//This code if from Microchip but is unused currently.
void uart_send_hex_ascii(unsigned char display_data)
{

	//unsigned char temp;
	//temp = ((display_data & 0xF0)>>4);
	//if (temp <= 0x09)
	//	Putchar(temp+'0');
	//else
	//	Putchar(temp+'0'+0x07);
        //
	//temp = display_data & 0x0F;
	//if (temp <= 0x09)
	//	Putchar(temp+'0');
	//else
	//	Putchar(temp+'0'+0x07);

	//Putchar('\r');
	//Putchar('\n');
}

void serial_init(void)
{

    // calculate values of SPBRGL and SPBRGH based on the desired baud rate
    //
    // For 8 bit Async mode with BRGH=0: Desired Baud rate = Fosc/64([SPBRGH:SPBRGL]+1)
    // For 8 bit Async mode with BRGH=1: Desired Baud rate = Fosc/16([SPBRGH:SPBRGL]+1)



    TXSTAbits.BRGH=1;       // select low speed Baud Rate (see baud rate calcs below)
    TXSTAbits.TX9=0;        // select 8 data bits
    TXSTAbits.TXEN=1;     // enable transmit
    BAUDCONbits.BRG16=0;

    RCSTAbits.SPEN=1;       // serial port is enabled
    RCSTAbits.RX9=0;        // select 8 data bits
    RCSTAbits.CREN=1;       // receive enabled


    SPBRG=25;               //38,400bps-ish
                            //BRG16=0, 7=31.25k, 25=9.615k

    PIR1bits.RCIF=0;        // make sure receive interrupt flag is clear
    PIE1bits.RCIE=1;        // enable UART Receive interrupt


         __delay_ms(10);        // give time for voltage levels on board to settle

}


void init_io(void) {
    ANSEL = 0x00;         
    ANSELH = 0x00;

    TRISAbits.TRISA0 = 0; // output
    TRISAbits.TRISA1 = 0; // output
    TRISAbits.TRISA2 = 0; // output
    TRISAbits.TRISA4 = 0; // output
    TRISAbits.TRISA5 = 0; // output



    TRISBbits.TRISB4 = 0; // output
    TRISBbits.TRISB5 = 1; // input (RX UART)
    TRISBbits.TRISB6 = 0; // output
    TRISBbits.TRISB7 = 0; // output (TX UART)

    LATC = 0x00;

    TRISCbits.TRISC0 = 1; // AN4
    TRISCbits.TRISC1 = 1; // 1-wire data
    TRISCbits.TRISC2 = 0; // 
    TRISCbits.TRISC3 = 0; // 
    TRISCbits.TRISC4 = 0; // 
    TRISCbits.TRISC5 = 0; // output
    TRISCbits.TRISC6 = 1; // input
    TRISCbits.TRISC7 = 1; // input

}


void init_adc (void)
{
    ANSELbits.ANSEL4=1;         //PORTC.0
    ADCON2bits.ADCS = 0x02;     //Fosc/32
    ADCON2bits.ADFM=0;          //left oriented
    ADCON1=0x00;
}

void read_adc (void)
{
    ADCON0bits.CHS0 = 0;        // AD4
    ADCON0bits.CHS1 = 0;
    ADCON0bits.CHS2 = 1;
    ADCON0bits.CHS3 = 0;
    ADCON0bits.ADON = 1;        // A/D ON
    __delay_us(5);

    ADCON0bits.GO   = 1;        // ..GO!

    __delay_us(5);

        while (ADCON0bits.GO) continue;              //wait for conversion
        an4_value = ADRESH;                          //AN4 value
}

void one_wire_reset(void) {
    device_present = 0x00;
    TRISCbits.TRISC1 = 0;
    LATCbits.LATC1 = 0;
    __delay_us(240);        //delay 480 us
    __delay_us(240);
    TRISCbits.TRISC1 = 1;
    __delay_us(70);
    if (!PORTCbits.RC1) {
            device_present = 0x01;
    }
    __delay_us(205);        //delay 410 us
    __delay_us(205);
}

//this looks a lot like the Microchip code, it was not I just happened to be on the right track.
void one_wire_tx_bit(unsigned char txbit) {         // write a bit
    if (txbit) {
    TRISCbits.TRISC1 = 0;
    LATCbits.LATC1 = 0;
    __delay_us(6);    
    TRISCbits.TRISC1 = 1;
    __delay_us(64);      
    }
    else {      
    TRISCbits.TRISC1 = 0;
    LATCbits.LATC1 = 0;
    __delay_us(60);    
    TRISCbits.TRISC1 = 1;
    __delay_us(10);    
    }
}

//from Microchip AN1199 code, renamed and slightly modified to match my software
/**********************************************************************
* Function:        void OW_write_byte (unsigned char write_data)
* PreCondition:    None
* Input:		   Send byte to 1-wire slave device
* Output:		   None
* Overview:		   This function used to transmit a complete byte to slave device.
*				   
***********************************************************************/
void one_wire_tx_byte (unsigned char write_data)
{
	unsigned char loop;
	
	for (loop = 0; loop < 8; loop++) 	{ 		one_wire_tx_bit(write_data & 0x01); 	//Sending LS-bit first 		write_data >>= 1;					// shift the data byte for the next bit to send
	}	
}	


//from Microchip AN1199 code: I gathered the essence of this but seeing as I am not using most of the AN1199 code
//and this would not work with XC8 I had to re-write this.
/**********************************************************************
* Function:        unsigned char OW_read_bit (void)
* PreCondition:    None
* Input:		   None
* Output:		   Return the status of the OW PIN
* Overview:		   This function used to read a single bit from the slave device.
*				   
***********************************************************************/

unsigned char one_wire_rx_bit (void)
{
	unsigned char read_data; 
        read_data = 0x00;
	//reading a bit 
	TRISCbits.TRISC1 = 0;
        LATCbits.LATC1 = 0; 						// Drive the bus low
	__delay_us(6);						// delay 6 microsecond (us)
	TRISCbits.TRISC1 = 1;  						// Release the bus
	__delay_us(9);						// delay 9 microsecond (us)

        if (PORTCbits.RC1) {                                    //read 1 or 0
            read_data = 0x01;
        }

	__delay_us(55);						// delay 55 microsecond (us)	
	return read_data;
}


/**********************************************************************
* Function:        unsigned char OW_read_byte (void)
* PreCondition:    None
* Input:		   None
* Output:		   Return the read byte from slave device
* Overview:		   This function used to read a complete byte from the slave device.
*				   
***********************************************************************/

unsigned char one_wire_rx_byte (void)
{
	unsigned char loop, result=0;
	
	for (loop = 0; loop < 8; loop++)                // here we are reading 8 bits (1 byte) 	{ 		 		result >>= 1; 				// shift the result to get it ready for the next bit to receive
		if (one_wire_rx_bit())
		result |= 0x80;				// if result is one, then set MS-bit
	}
	return result;					
}	

void one_wire_conversion_pulse(void) {
    	TRISCbits.TRISC1 = 0;
        LATCbits.LATC1 = 1; 		 //For T conv we drive the DQ line high for 750ms (12bit)
	__delay_us(250);                 // delay 
	__delay_us(250);                  
        __delay_us(250);                  
	TRISCbits.TRISC1 = 1; 
        LATCbits.LATC1 = 0;             //just in case this causes problems elsewhere                              
}

int main(void) {

    init_io();

    // set up oscillator control register, using internal OSC at 16MHz.
    OSCCONbits.IRCF = 0x07; //set OSCCON IRCF bits to select OSC frequency 16MHz
    OSCCONbits.SCS = 0x02; //set the SCS bits to select internal oscillator block

    //RCONbits.IPEN = 0;          //dsiable priority levels

    INTCONbits.PEIE = 1;        // Enable peripheral interrupt
    INTCONbits.GIE = 1;         // enable global interrupt


    init_adc();                 //unused but AN4 is there if I need it
    serial_init();

    uart_send ('x');

        LATAbits.LATA0 = 0; //this is just for debugging with an LA..
        __delay_us(1);
        LATAbits.LATA0 = 1; //also confirms oscillator setup is correct.. 1us width
        __delay_us(1);
        LATAbits.LATA0 = 0;

    while (1) {

        one_wire_reset();

        if (device_present) {
            LATCbits.LATC2 = 1;             //this is a 1-wire device out there for debugging

            one_wire_tx_byte(0xCC);         //skip-rom (similar to a broadcast)

            one_wire_tx_byte(0x44);         //do a temp conversion

            one_wire_conversion_pulse();    // hold DQ line high for 750ms

            one_wire_reset();

            //add additional check here later

            one_wire_tx_byte(0xCC);         //skip-rom (similar to a broadcast)

            one_wire_tx_byte(0xBE);         //read scratch pad

            for(i = 0; i<9; i++)            //reading all 9 bytes on the T-Sense
   		rxbuff[i] = one_wire_rx_byte();
            // T-Sense
            //  Byte 0 LSB of Temp
            //  Byte 1 MSB of Temp and sign

            // LSB
            //  2^3 2^2 2^1 2^0 2^-1 2^-2 2^-3 s^-4
            // MSB
            // S S S S S 2^6 2^5 2 ^ 4



            temperature = 0;
            f = 0.0625;

            //z[0] = rxbuff[1];
            //x = atoi(z);
            x = rxbuff[1];

            if (x & 0b10000000) {
                uart_send('-');
            } else {
                uart_send('+');
            }
            
            x = x & 0b00000111;

            int_temp = 0;

            int_temp = rxbuff[0];

            if (x & 0b00000001)
                int_temp = int_temp + 0x100;
            if (x & 0b00000010)
                int_temp = int_temp + 0x200;
            if (x & 0b00000100)
                int_temp = int_temp + 0x400;

            temperature = int_temp * f;
            
            int_temp = temperature;

            itoa(z, int_temp, 10);
            write_uart(z);
            uart_send('.');

            d = temperature - int_temp;

            decm = d * 1000;

            //page 374 of XC8 user guide
            ltoa(buf,decm,10);  //long conversion to buffer
            y=strlen(buf);  //uh, adding leading zeros..
            y=3-y;      //probably a better way of doing thing
            while (y)       //first figure out how many zeros
            {
                uart_send('0');  //missed 3-string length
                y=y-1;  //then send them until done
            }   
            write_uart (buf);
        
            uart_send(0x0A);        //LF
            uart_send(0x0D);        //CR

            //temperature   float temperature
            //int_temp      interger value of temperature

            __delay_10ms(254);
        }

    }
    return (EXIT_SUCCESS);
}

 

 

 

 

 

 

Electronics LiPo Tools and Test Equipment

Breadboard Buddy Pro on the bench

I got a great gift in the mail yesterday! I sneak preview of the up coming Breadboard Buddy Pro. This one is a development board but it looks good and worked even better.

New breadboard buddy with a LiPo battery interface for the hardware hacker on the go!
New breadboard buddy with a LiPo battery interface for the hardware hacker on the go!

I am working on a little project that reads data from Maxim 1-wire temperature sensors (coming soon!) so I put the new BBB into action. The LiPo charger seemed to work just fine.. power was all good. The only thing that I noticed, and honestly I haven’t read the documentation on AdamSoftTech’s Tindie store site, when running on the battery the power supply will only provide 3.3V, not 5.0; the 5.0V rail goes dark .. so no boost on board but in reality that’s not a surprise as there isn’t any big inductors sitting on the PCB.

This product is definitely going into my electronics hobbyist go-bag! My favorite feature on this new product is the handy LiPo battery connector making development on the road easy. Whenever I’m on a trip for training, or working out-of-town I enjoy bringing a few basics to work on some project I’ve had back-burnered but can be worked on by breadboard. I like to pack light and this tool helps out greatly.

Besides the LiPo battery option, battery is not included, I really like the fact he crammed a USB-serial bridge on a power supply board. The RX/TX lights are nice and I imagine for people putting a chip in board the reset button is handy. I use plug-in dev boards and almost everyone puts a reset button on those. I used both 5V then switched to 3.3V .. more than enough current at 500mA of course.

The BBB Pro is also pretty robust: In a silly mistake I accidentally put my logic analyzer ground on the 5V plane.. well the BBB Pro folded back and protected itself.. before it did that though it delivered enough current to melt down my micrograbber…  I’m very thankful I caught it quickly and my LA, USB ports and the BBB Pro are all just fine. The clip was replaced and made its way into my Bag Of Shame. The micrograbber will fit in well within the BOS, which includes such things as an 18F26K22 I melted down.. a handful of MOSFETs (a bag favorite), and assorted other parts I’ve cooked making dumb mistakes.

On the photo above you also notice two new breadboard favorites:

The tinyLEDx4 from AtomSoftTech and a board I made recently for attaching jumpers for my scope and logic analyzer. I sent in a sample and of course Jason (with AST) came up with a revised version of the clip holder which was better designed than mine in a few minutes.. thankfully I don’t do this for a living! 😀