2010-12-28

Stepper Motors library ported from Arduino to Pinguino


This library was ported from Stepper library from Arduino project,
Same samples works with minimum changes!
http://arduino.cc/en/Reference/Stepper

You need add a 1µF or 10µF capacitor between GND and VCC on pinguino board.
Tested with a PM35-048 stepper and ULN2003a / ULN2803a drivers.

DOWNLOAD


INSTALL
1- Copy Stepper.lib/stepper.c and Stepper.lib/stepper.h to pinguino/tools/share/sdcc/include/pic16/
2- Copy Stepper.lib/stepper.pdl to pinguino/lib

Sample:

/*
 * Based on MotorKnob Stepper Library from Arduino Project
 *
 * A stepper motor follows the turns of a potentiometer
 * (or other sensor) on analog input 0.
 *
 * http://www.arduino.cc/en/Reference/Stepper
 * 
 * Pinguino port by Anunakin 
 * For use this sample on Pinguino boards, 
 * you need add a 10uF or less capacitor 
 * between GND and VCC on pinguino board.
 */
#define PIC18F4550
#define LED 4
#define POT 13
// change this to the number of steps on your motor
// PM35S-048
#define STEPS 48
// specify the number of steps of the motor and the pins it's
// attached to
// the previous reading from the analog input
int previous = 0;
void setup()
{
  stepper(STEPS, 0, 1, 2, 3);
  //stepper(STEPS, 0, 1);
  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(100);
  
  pinMode(POT,INPUT);
  pinMode(LED,OUTPUT);
}
void loop()
{
   // get the sensor value
  int val = analogRead(POT);
  val = (int)(val*1/16);
  
  // move a number of steps equal to the change in the
  // sensor reading
  if (val != previous){    
    stepper.step(val - previous);
  }
    
    digitalWrite(LED,HIGH);
    delay(50 + val);
  //}
  digitalWrite(LED,LOW);
  delay(50);
  
  //remember the previous value of the sensor
  previous = val;
}

GLCD Pinguino library revision 1.6.1

A small patch on PORTA/PORTC switch routine.

GLCD_pinguino_library_v1.6.1.zip

2010-12-27

GLCD Pinguino library new version 1.6


I made a new version of GLCD Pinguino library, this already tested with Pinguino beta 9.05, this have many improves on coding way.

Now we can:
- Use GLCD.PrintFloat(float number, presision) function for print decimal numbers, with #define USEFLOATS()

- Choose what port library uses for display control PORTA or PORTC, with #define USEPORTA()


Download GLCD 1.6 Here!

2010-12-20

2010-12-16

Pinguino i2c OLED Display




Thanks for help of JPMandon, we have OLED Display working
with libi2c on pinguino Board!

Pinguino full sourcecode here:
OLED.zip
//Program for I2C communication with a 128x64 OLED Display (http://www.seeedstudio.com)
//Marcus Fazzi 2010
#define LED 13
#define I2C_address 0x3c    //i2c address of Display
#include <libI2C.c>
//For working with strings strlen() function
// #include <string.h>
#include "data.c"
unsigned char fill_OLED = 0x55;
unsigned char fill_string1[13]="Pinguino OLED";
unsigned char fill_string2[11]="OLED 128x64";
unsigned char fill_string3[16]="0123456789ABCDEF";
unsigned char fill_string4[2]="SS";
//=======================
void sendcommand(unsigned char com)
{   
  short dt[2] =  { 0x80, com }; //command mode
  I2C_write(I2C_address, dt, 2);
  I2C_STOP(); //stop transmitting
}
//===================================
void SendChar(unsigned char dat)
{
  short dt[2] =  { 0x40, dat }; //data mode
  I2C_write(I2C_address, dt, 2);
  I2C_STOP();    //stop transmitting
}
//===================================
void setXY(unsigned char row,unsigned char col)
{
  sendcommand(0xb0 + row); //set page address
  sendcommand(0x00 + (8 * col & 0x0f)); //set low col address
  sendcommand(0x10 + ((8 * col >> 4) & 0x0f)); //set high col address
}
//==================================
void clear_display()
{
  unsigned char i,k;
  for(k=0;k<8;k++)
  {     
    setXY(k,0);    
    {
      for(i=0;i<128;i++) //clear all COL
      {
        SendChar(0);
      }
    }
  }
}
//==================================
void printChar(unsigned char ascii)
{
  unsigned char i;
  for(i=0;i<8;i++)
  {
    SendChar(myFont[ascii-0x20][i]);
  }
}
//==================================
void sendStr(unsigned char *string, unsigned char len)
{
  unsigned char i, j;
  //setXY(0,0);    
  for(i=0;i<len;i++)
  {
    for(j=0;j<8;j++)
    {
      SendChar(myFont[*string-0x20][j]);
                //SendChar(*string);
      delay(10);
    }
    *string++;
  }
}
//=================================
void init_OLED(void)
{
  sendcommand(0xae);            //display off
  delay(50); 
//  sendcommand(0xa0);          //seg re-map 0->127(default)
//  sendcommand(0xa1);          //seg re-map 127->0
//  sendcommand(0xc8);
//        delay(1000);
  sendcommand(0xaf);            //display on
  delay(50);
}
void setup()
{
   delay(500);
   init_I2C();
        //SSPADD=19;  //Slow mode
        
   init_OLED();
        delay(10);
        clear_display();
   delay(50);
   
   pinMode(LED, OUTPUT);  
   
}
//========================
void loop()
{
  short i;
  
  clear_display();
  delay(50);
  sendcommand(0x20);          //Set Memory Addressing Mode
  sendcommand(0x02);          //Set Memory Addressing Mode ab Page addressing mode(RESET)  
 
  sendcommand(0xa6);                    //Set Normal Display (default)
  setXY(3,2);
  sendStr(fill_string1, 13);
  setXY(4,3);
  sendStr(fill_string2, 11);
  
  delay(2000);
  sendcommand(0xa7);                    //Set Inverse Display  
  delay(2000);
  clear_display();
  delay(50);  
  setXY(0,0);
  sendcommand(0xa6);                    //Set Normal Display
  sendcommand(0xae);                            //display off
  sendcommand(0x20);                    //Set Memory Addressing Mode
  sendcommand(0x00);                    //Set Memory Addressing Mode ab Horizontal addressing mode
  
  for(i=0;i<128*8;i++)                  //write a 128x64 picture
  {
    SendChar(logo[i]);
  }
  
  sendcommand(0xaf);                            //display on
  delay(2000);
  sendcommand(0xa7);                    //Set Inverse Display
  delay(2000);  
 /*
  while(1)
  {
    //sendcommand(0xa6);  Set Normal Display
    sendcommand(0x29);  //Vertical and Horizontal Scroll Setup
    sendcommand(0x00);  //dummy byte
    sendcommand(0x00);  //define page0 as startpage address
    sendcommand(0x00);  //set time interval between each scroll ste as 6 frames
    sendcommand(0x07);  //define page7 as endpage address
    sendcommand(0x01);  //set vertical scrolling offset as 1 row
    sendcommand(0x2f);  //active scrolling
    delay(3000);
  };
  */
}

You can see datasheet, arduino sample, and buy one at:
http://www.seeedstudio.com/depot