Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Displays / Re: Which LCD display should I buy? on: February 05, 2012, 07:33:03 pm
I have purchased several 1602 modules (backlit 16x2) from China via eBay at very affordable prices. They work great - see my post about libraries (http://arduino.cc/forum/index.php/topic,90526.0.html). You can see what is available on eBay at http://tinyurl.com/7qv3zwn
32  Using Arduino / Displays / Shift Register Libraries for LCD Displays on: February 05, 2012, 07:26:07 pm
I am working on a project where, ultimately, I will be driving a 16x2 1602 LCD with a ATtiny85. For now, however, I am testing Shift Register libraries, and there are several out there. I am testing several and will, eventually, pick one. So far I have tested ShiftLCD by Chris Parish and LiquidCrystal_SR by Francisco Malpartida. They both work well but require significantly different wiring. I have posted my test "Hello World" for both libraries below. The wiring differences are noted. I thank both Chris and Francisco for generously donating the libraries to the community.

First, with LiquidCrystal_SR:
Code:
#include <LiquidCrystal_SR.h>

/*
  ShiftLCD Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The ShiftLCD library works with
 all LCD displays that are compatible with the Hitachi HD44780 driver.
 There are many of them out there, and you can usually tell them by the
 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the number of seconds since reset.
 
  The circuit:
 
 ---Shift Register 74HC595---
 * SR SER - Pin 14 to Arduino pin PD2
 * SR RCK - Pin 12 to Arduino pin PD3 and (LCD E 1602 Pin 6)
 * SR SCK - Pin 11 to Arduino pin PD4
 * SR GND - Pin  8 to Ground
 * SR VCC - Pin 16 to +5v
 * SR OE - Pin 13 to Ground
 * SR SCLR - Pin 10 to +5v
 -----Shift Reg to LCD--------
 * SR QG - Pin 6 to D7 (LCD 1602 Pin 14)
 * SR QF - Pin 5  to D6 (LCD 1602 Pin 13)
 * SR QE - Pin 4  to D5 (LCD 1602 Pin 12)
 * SR QD - Pin 3  to D4 (LCD 1602 Pin 11)
 * SR QC - Pin 2  to LCD RS (LCD 1602 Pin 4)
 -----LCD HD44780-------------
 * Vss to Ground    (LCD 1602 Pin 1)
 * Vdd to +5V       (LCD 1602 Pin 2)
 * Vo  to 10k Wiper (LCD 1602 Pin 3)
 * R/W to Ground    (LCD 1602 Pin 5)
 * LEDA  to +5v     (LCD 1602 Pin 15)
 * Gnd to LEDK via 330 Ohm resistor  (LCD 1602 Pin 16)
 
 The schematic at this link is:
 http://code.google.com/p/arduinoshiftreglcd/ see
 the last schematic labled "Latched shiftregister"

 */
 
#define  DATAPIN  2
#define  CLOCKPIN 4
#define  STROBEPIN 3
#define  MAXCOLUMNS  16
#define  MAXLINES  2


LiquidCrystal_SR lcd(DATAPIN, CLOCKPIN, STROBEPIN);

void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(MAXCOLUMNS, MAXLINES);
  // Print a message to the LCD.
  lcd.print("Hello, World!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);  //lcd.setCursor(column, row);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

Next with ShiftLCD:
Code:
#include <ShiftLCD.h>

/*
  ShiftLCD Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The ShiftLCD library works with
 all LCD displays that are compatible with the Hitachi HD44780 driver.
 There are many of them out there, and you can usually tell them by the
 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the number of seconds since reset.
 
  The circuit:
 
 ---Shift Register 74HC595---
 * SR SER - Pin 14 to Arduino pin PD2
 * SR RCK - Pin 12 to Arduino pin PD3
 * SR SCK - Pin 11 to Arduino pin PD4
 * SR GND - Pin  8 to Ground
 * SR VCC - Pin 16 to +5v
 * SR OE - Pin 13 to Ground
 * SR SCLR - Pin 10 to +5v
 -----Shift Reg to LCD--------
 * SR QA - Pin 15 to D7
 * SR QB - Pin 1  to D6
 * SR QC - Pin 2  to D5
 * SR QD - Pin 3  to D4
 * SR QG - Pin 6  to LCD Enable (LCD 1602 Pin 6)
 * SR QH - Pin 7  to LCD RS (LCD 1602 Pin 4)
 -----LCD HD44780-------------
 * Vss to Ground    (LCD 1602 Pin 1)
 * Vdd to +5V       (LCD 1602 Pin 2)
 * Vo  to 10k Wiper (LCD 1602 Pin 3)
 * R/W to Ground    (LCD 1602 Pin 5)
 * LEDA  to +5v     (LCD 1602 Pin 15)
 * Gnd to LEDK via 330 Ohm resistor  (LCD 1602 Pin 16)
 
 The schematic at this link is correct except that, in this implementation,
 The MOSFET circuit is replaced by a 330 ohm resistor (see above).
 http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
 
 Library modified from the original LiquidCrystal Library
 This example originaly by Tom Igoe, Jul 2009
 Example modified for use with ShiftLCD
 Chris Parish, January 12th 2010
 */
 
#define  DATAPIN  2
#define  CLOCKPIN 4
#define  LATCHPIN 3
#define  MAXCOLUMNS  16
#define  MAXLINES  2
#define  FOURBIT  4


ShiftLCD lcd(DATAPIN, CLOCKPIN, LATCHPIN, FOURBIT);

void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(MAXCOLUMNS, MAXLINES);
  // Print a message to the LCD.
  lcd.print("Hello, World!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);  //lcd.setCursor(column, row);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
https://github.com/marcmerlin/NewLiquidCrystal
33  Using Arduino / Programming Questions / [SOLVED] ATtiny85 SoftSerial known to work? on: January 31, 2012, 05:50:06 pm
I have searched a lot for a SoftSerial library that is known to work for the ATtiny85 or instructions on how to get the Arduino SoftSerial library to work for the ATtiny85 but have  not found a solution verified for the ATtiny85. I did find assembler code drivers in Atmel's AVR305, AVR304, AVR307 that look promising, although not exactly ATtiny85 specific, but I'd prefer C code. Does anyone here know of a  SoftSerial library that is known to work for the ATtiny85??
34  Using Arduino / Networking, Protocols, and Devices / NT-T02B/ZABR1 cheap Chinese wireless serial on: January 21, 2012, 07:11:29 pm
I have been testing the NT-T02B transmitter and ZABR1 receiver, which are cheap Chinese wireless serial links available on eBay (search for 433 MHz  Arduino). For mine, I paid $5.49 including postage. I did not bother to connect proper length antennas (18cm) so my reliable operation distance was short. The VirtualWire library is not up to Arduino 1.0, so I had to replace WProgram.h with Arduino.h in the library files in order to successfully compile.

I setup the transmitter to sequentially number the transmitted messages so that I could look for drops on the receive side. See attached screen capture.

Working sketches are below.

For the transmit end:
Code:
#include <VirtualWire.h>
#include <string.h>

// rf_tx.ino
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Original by: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
//

#undef int
#undef abs
#undef double
#undef float
#undef round

int count = 0;

void setup()
{
    Serial.begin(9600);  // Debugging only
    Serial.println("Transmitter setup");

    // Initialise
    vw_set_tx_pin(12);    // Set tx pin (default is 12)
    vw_setup(2000); // Bits per sec
}

void loop()
{
    //const char *msg = "hello world";
    char msg[VW_MAX_MESSAGE_LEN];
    char scount[VW_MAX_MESSAGE_LEN];
    
    memset(msg,0,VW_MAX_MESSAGE_LEN-1);
    strcat(msg,"Message ");
    itoa(count++, scount, 10);
    strcat(msg,scount);
    
    digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);
    Serial.println(msg);
    delay(200);
}

and for the receive end:
Code:
#include <VirtualWire.h>
// rf_rx.ino
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Original Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley


#undef int
#undef abs
#undef double
#undef float
#undef round

void setup()
{
    Serial.begin(9600); // Debugging only
    Serial.println("Rx setup");

    // Initialise the IO and ISR
    vw_set_rx_pin(11);    // Set Rx pin (defaults to 11)
    vw_setup(2000); // Bits per sec
    vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    // Get the last message received (without byte count or FCS)
    // Copy at most *buflen bytes, set *buflen to the actual number copied
    // Return true if there is a message and the FCS is OK
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
int i;

        buf[buflen] = 0;        // NULL terminate string received
        digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Rx ");
        Serial.print(buflen, DEC);
        Serial.print(" ctrs - ");
        Serial.println((char *)buf);
        digitalWrite(13, false);
    }
}
35  Using Arduino / Motors, Mechanics, and Power / Great Stepper Application on: January 17, 2012, 05:30:13 pm
What a great use of stepper motors, other than CNC of course. Daniel Scheinert uses the accelstepper library for his video ramping aid.

Watch the video:
 

His blog discusses his stepper work at http://www.danielschweinert.com/blog/files/tag-stepper.html
36  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 17, 2012, 05:14:20 pm
I was able to get the Arduino stepper library to perform better for the 28BYJ-48, but, of course, the  Arduino stepper library is limited and does not support acceleration/deceleration.  Here is working Arduino stepper library code for the 28BYJ-48:

Code:
/*
  Derived from YourDuino.com Example Software Sketch
   Small Stepper Motor and Driver, by:
   terry@yourduino.com
*/

#include <Stepper.h>
//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

#define STEPS  64   //Number of steps per revolution

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4  and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing of 28BYJ48
Stepper small_stepper(STEPS, motorPin1, motorPin3, motorPin2, motorPin4);

int  Steps2Take;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  small_stepper.setSpeed(200);
}/*--(end setup )---*/

void loop()
{
  // sweep 1 turn each way
  small_stepper.setSpeed(200);  
  Steps2Take  =  2048;  // Rotate CW
  small_stepper.step(Steps2Take);
  delay(2000);
  
  small_stepper.setSpeed(200);  // 200 a good max speed??
  Steps2Take  =  -2048;  // Rotate CCW
  small_stepper.step(Steps2Take);
  delay(2000);

}

Most recently, I have been experimenting with the powerful accelstepper library (http://www.open.com.au/mikem/arduino/AccelStepper). It supports acceleration/deceleration and much more. I posted a short demo video of a 28BYJ-48 being driven by the accelstepper library in full-step mode. It actually is more impressive in half-step mode but I didn't make a video of that. The video is at: http://youtu.be/1F3240hCHE4

The sketch used in the video is shown below:
Code:
// accellsteppertest.ino
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Derived from example code by Mike McCauley
// Set for 28BYJ-48 stepper

#include <AccelStepper.h>

#define FULLSTEP 4
#define HALFSTEP 8

//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper2(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup()
{    
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}

void loop()
{
  //Change direction at the limits
  if (stepper2.distanceToGo() == 0) {
    stepper2.moveTo(-stepper2.currentPosition());
  }
  stepper2.run();
}

The accelstepper library has many useful features. Check it out!
37  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 15, 2012, 02:04:19 pm
For those of you interested in greater technical detail on controlling a stepper motor, take a look at Atmel Corp's Application Note  titled "AVR446: Linear speed control of stepper motor". Lots of math there for you number crunchers.   it is an PDF located at:
http://www.atmel.com/dyn/resources/prod_documents/doc8017.pdf
38  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 14, 2012, 08:17:21 pm
PORTB's advantage is probably moot, since we are throwing in delays anyway. The only advantage is to eliminate those microseconds of delay when setting two ports simultaneously. However, the difference is not trivial - is about 95 times faster, according to John Boxall's blog: http://tronixstuff.wordpress.com/tag/portb/

However, using PORTx commands introduce a lot of risk, reduces portability and readability and should be avoided unless truly needed.

I just wanted to see if I could get it working and I will NOT be using PORTx for a stepper application.
39  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 14, 2012, 05:17:55 pm
I rewrote my original stepper test to utilize direct port manipulation. I hesitated in doing this until I was positive that writes to PORTB were not going to mess up the crystal on PB6 & PB7 - it does not. DO NOT TRY THIS SKETCH unless your setup is identical to the sketch. The PORTB writes only write to Digital pins 8-to-13. If you use different pins then you MUST rewrite the sketch. Read the other warning in the sketch. This sketch only been tested on an Arduino NANO.

Code:
// WARNING: USE AT YOUR OWN RISK!!!
// Do not use this script if your Arduino doesn't use a Atmega328 or Atmega168
// It is only been tested on an Arduino NANO
// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, which is readily available on eBay, using a ULN2003
// interface board to drive the stepper.
//////////////////////////////
// The Atmega328p chips used on the Arduino board have three ports.
// We are interested in port B:
// We are using Arduino Digital bits 8-11, which map to Atmega328p PB0-PB3
// B (digital pin 8 to 13)
// NOTE: as tested by anescient, there's no harm in writing to PORTB as long as DDRB[6:7] are 0
// Read: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261361330
////////////////////////////////////////////////
// The speed and direction of the stepper motor is determined
// by adjusting a 1k-ohm potentiometer connected to Arduino pin A2.
// When the potentiometer is rotated fully counterclockwise, the motor
// will rotate at full counterclockwise speed. As the potentiometer is
// rotated clockwise, the motor will continue to slow down until is
// reaches its minimum speed at the the potentiometer's midpoint value .
// Once the potentiometer crosses its midpoint, the motor will reverse
// direction. As the potentiometer is rotated further clockwise, the speed  
// of the motor will increase until it reaches its full clockwise rotation
// speed when the potentiometer has been rotated fully clockwise.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

int motorSpeed = 0;     //variable to set stepper speed
int potPin = 2; //potentiometer connected to A2
int potValue = 0; //variable to read A0 input


//////////////////////////////////////////////////////////////////////////////
void setup() {
  //declare the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){

  potValue = analogRead(potPin);     // read the value of the potentiometer
  Serial.println(potValue);          // View full range from 0 - 1024 in Serial Monitor
  if (potValue < 535){               // if potentiometer reads 0 to 535 do this
    motorSpeed = (potValue/15 + 5);  //scale potValue to be useful for motor
    clockwise();                     //go to the ccw rotation function
  }
  else {                             //value of the potentiometer is 512 - 1024
    motorSpeed = ((1024-potValue)/15 + 5); //scale potValue for motor speed
    counterclockwise(); //go the the cw rotation function
  }
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)

void counterclockwise (){
  // 1
  PORTB = 0b0001;
  delay(motorSpeed);
  // 2
  PORTB = 0b0011;
  delay(motorSpeed);
  // 3
  PORTB = 0b0010;
  delay(motorSpeed);
  // 4
  PORTB = 0b0110;
  delay(motorSpeed);
  // 5
  PORTB = 0b0100;
  delay(motorSpeed);
  // 6
  PORTB = 0b1100;
  delay(motorSpeed);
  // 7
  PORTB = 0b1000;
  delay(motorSpeed);
  // 8
  PORTB = 0b1001;
  delay(motorSpeed);
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
//delay "motorSpeed" between each pin setting (to determine speed)

void clockwise(){
   // 1
   PORTB = 0b1000;
  delay(motorSpeed);
  // 2
  PORTB = 0b1100;
  delay(motorSpeed);
  // 3
  PORTB = 0b0100;
  delay(motorSpeed);
  // 4
  PORTB = 0b0110;
  delay(motorSpeed);
  // 5
  PORTB = 0b0010;
  delay(motorSpeed);
  // 6
  PORTB = 0b0011;
  delay(motorSpeed);
  // 7
  PORTB = 0b0001;
  delay(motorSpeed);
  // 8
  PORTB = 0b1001;
  delay(motorSpeed);
}

Now if I can determine the optimal "motorspeed" value then I can optimize the stepper's functionality.
40  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 14, 2012, 05:10:48 pm
sbright33 - your sketch posted on January 13, 2012, 06:51:43 PM is missing declarations for cw() and ccw().

Also, has your testing with microsecond delays determined an optimal delay in microseconds after doing the stepper write?
41  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 13, 2012, 02:16:04 pm
I haven't tried either of your sketches yet but you have been busy. Given your comments about heat and 12-volt operation apparently you are putting a lot of stress testing with your stepper(s).
42  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 12, 2012, 05:50:46 pm
Yes, I considered trying the bitmasks but was a bit lazy when I wrote the code.
43  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 12, 2012, 04:12:10 pm
sbright33 - Thank you for reporting your test results. 8 is better than 4, after all.
44  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 11, 2012, 12:36:59 pm
I do not personally know of a specific advantage other than this is how the manufacturer says that it should be done. It is intuitive that the manufacturer would not arbitrarily specify eight steps for no reason whatsoever. To turn the question around, do you anticipate some advantage for you to use the library function?
45  Using Arduino / Motors, Mechanics, and Power / Re: 28BYJ-48 5-Volt Stepper on: January 11, 2012, 07:24:53 am
Eight steps because the motor requires eight steps. See the manufacturer's spec sheet at http://tinyurl.com/6tt337n. I attempted to attach it but the forum complains that the upload area is full. However, the stepper library can be made to work. See: http://arduino-info.wikispaces.com/SmallSteppers
Pages: 1 2 [3] 4