Show Posts
Pages: [1]
1  Using Arduino / Displays / Re: Help please on: May 05, 2013, 04:37:37 am
I'm using optocoupler to count the RPM of a DC motor and her is the code , The problem is that the LCD write RPM=0 however i run the dc motor

Quote
             
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;

// include the library code:
#include <GLCDI2C.h>
#include <Wire.h>

// Color definitions
#define   BLACK           0x0000
#define   BLUE            0x001F
#define   RED             0xF800
#define   GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF


unsigned int maxX = 160;  // LCD x-resolution
unsigned int maxY = 128;  // LCD y-resolution
unsigned char i2cAddress = 0x46;  // LCD module I2C address
unsigned int counter;
unsigned int tmp;
GLCDI2C lcd = GLCDI2C(maxX, maxY, i2cAddress);


void rpm_fun()
 {
  
      rpmcount++;
 }

void setup()
 {
   delay(500);
  Wire.begin();  
  lcd.init();
  
   attachInterrupt(0, rpm_fun, FALLING);

  

   rpmcount = 0;
   rpm = 0;
   timeold = 0;
 }

 void loop()
 {
  
   delay(1000);
  
   detachInterrupt(0);
  
   rpm = 30*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;

  
   delay(500);
   lcd.setColor(BLACK);
   lcd.clear();
   lcd.fontType(FONT_SMALL);
   lcd.setColor(WHITE);
   lcd.cursor(15,15);
  
   lcd.print("RPM=");
   lcd.print(rpm);
   delay(3000);

  
   attachInterrupt(0, rpm_fun, FALLING);
  }
2  Using Arduino / Displays / Help please on: May 04, 2013, 07:17:58 pm
I am doing a speed sensor project using optocoupler to count pulses  , I uses Color Graphic LCD with I2C Interface here is the link of the lcd http://www.web4robot.com/GraphicLCD.html     I don't know how to write a code to  link the optocoupler with the lcd  to print the rpm of a dc motor

http://www.web4robot.com/files/GLCD-FLEXEL.pdf

http://www.web4robot.com/files/GLCD-I2C.zip
Pages: [1]