Show Posts
Pages: [1] 2
1  Using Arduino / Microcontrollers / Curious about pin declare... on: May 04, 2013, 03:20:13 am
I had read a lot of arduino programs/ Textbook, they usually declare the pin by using "int", such as "int ledPin = 11;"

I wonder that using int(-32768 to 32767) to declare pin cost 2 bytes of memory;

but using byte(0 to 255) to declare pin only cost 1 byte of memory.

Why people always using int for declare pin but not byte ?

Thx.
2  Using Arduino / Motors, Mechanics, and Power / Re: I had a problem on L293D on: February 14, 2012, 01:11:56 pm
Many Thx.
I will re-solder the circuit and change the electronic component...

BTW, when I use analogwrite (arduino pin is PWM) to control the 1,2 Enable of L293D, there is a high frequency sound produced from the board;
I don't know what's going on, I guess the voltage (6V for small motor) I supplied is not enough, is it ?

Thx.
3  Using Arduino / Motors, Mechanics, and Power / Re: I had a problem on L293D on: February 13, 2012, 07:44:32 pm
The program mainly refer to the following :
http://www.e-shore.com.my/homepage/all-projects/193-ir-remote-control-mobile-robot.html

Here is the working code (stop at 800ms after each action)

Code:
//............ Import Library ...............
//
#include <IRremote.h>  // includes the IR Library - from Ken Shirriff's blog                                                                                                                                                                   
//
//............ Declare PIN Variables ............
//
const int FrontLED = 13;
//............ LEFT Gear Motor .................
const int MotorA1Pin =4;
const int MotorA2Pin = 2;
const int MotorENAPin = 3;
//............ RIGHT Gear Motor ................
const int MotorB1Pin = 8;
const int MotorB2Pin = 7;
const int MotorENBPin = 5;
//............ IR Receiver Pin ..................
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
//
//............ Arduino Setup ................
//
void setup()
{
// Serial.begin(9600);
//............ Configure pins ...............
pinMode(FrontLED,OUTPUT);
//............ LEFT Gear Motor .................
pinMode(MotorA1Pin,OUTPUT);
pinMode(MotorA2Pin,OUTPUT);
pinMode(MotorENAPin,OUTPUT);
//............ RIGHT Gear Motor ................
pinMode(MotorB1Pin,OUTPUT);
pinMode(MotorB2Pin,OUTPUT);
pinMode(MotorENBPin,OUTPUT);
//............ Enable Motors ...............
digitalWrite(MotorENAPin, HIGH);
digitalWrite(MotorENBPin, HIGH);
//............ Start IR receiver ............
irrecv.enableIRIn();
}
//
//............ Arduino Loop .................
//
void loop() {
//............ IR signal received ...........
if(irrecv.decode(&results))
{
//............ IR Input - 2 - Tank Motion _Forward
if(results.value==0xFD8877)
{
    motor(0,1,1,0);
}
//............ IR Input - 8 - Tank Motion_Backward
else if(results.value==0xFD9867)
{
    motor(1,0,0,1);
}
//............ IR Input - 4 - Tank Motion_Left
else if(results.value==0xFD28D7)
{
      motor(0,1,0,0);
}
//............ IR Input - 6 - Tank Motion_Right
else if(results.value==0xFD6897)
{
      motor(0,0,1,0);
}
//............ IR Input - 1 - Tank Motion_Fast Left
else if(results.value==0xFD08F7)
{
      motor(0,1,0,1);
}
//............ IR Input - 3 - Tank Motion_Fast Right
else if(results.value==0xFD48B7)
{
      motor(1,0,1,0);
}
//............ IR Input - 7 - Tank motion Right_backward
else if(results.value==0xFD18E7)
{
      motor(0,0,0,1);
}
//............ IR Input - 9 - Tank motion Left_backward
else if(results.value==0xFD58A7)
{
      motor(1,0,0,0);
}
//............ IR Input - 5 - Stop Motion
else if(results.value==0xFDA857)
{
      motor(0,0,0,0);
}
//............ IR Input - EQ - Turn on the LED
else if(results.value==0xFDB04F)
{
if (digitalRead(FrontLED)==HIGH)
{
digitalWrite(FrontLED,LOW);
}
else
{
  digitalWrite(FrontLED,HIGH);
}
}
//............ Receive the next value ...............
irrecv.resume();
//............ Short delay waiting for repeating IR signal
delay(300);
}
}
//
// Function to control the motor
// Non-return value subroutine
//
void motor(int MotorA1, int MotorA2, int MotorB1, int MotorB2) {
digitalWrite(MotorENAPin, HIGH);
digitalWrite(MotorENBPin, HIGH);
if (MotorA1==0) digitalWrite(MotorA1Pin,LOW);
if (MotorA2==0) digitalWrite(MotorA2Pin,LOW);
if (MotorB1==0) digitalWrite(MotorB1Pin,LOW);
if (MotorB2==0) digitalWrite(MotorB2Pin,LOW);
if (MotorA1==1) digitalWrite(MotorA1Pin,HIGH);
if (MotorA2==1) digitalWrite(MotorA2Pin,HIGH);
if (MotorB1==1) digitalWrite(MotorB1Pin,HIGH);
if (MotorB2==1) digitalWrite(MotorB2Pin,HIGH);
delay(800);
digitalWrite(MotorENAPin, LOW);
digitalWrite(MotorENBPin, LOW);
}

The following is the code which hang after receive any motor action. (Same code but different in the last paragraph)

Quote
//............ Import Library ...............
//
#include <IRremote.h>  // includes the IR Library - from Ken Shirriff's blog                                                                                                                                                                   
//
//............ Declare PIN Variables ............
//
const int FrontLED = 13;
//............ LEFT Gear Motor .................
const int MotorA1Pin =4;
const int MotorA2Pin = 2;
const int MotorENAPin = 3;
//............ RIGHT Gear Motor ................
const int MotorB1Pin = 8;
const int MotorB2Pin = 7;
const int MotorENBPin = 5;
//............ IR Receiver Pin ..................
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
//
//............ Arduino Setup ................
//
void setup()
{
// Serial.begin(9600);
//............ Configure pins ...............
pinMode(FrontLED,OUTPUT);
//............ LEFT Gear Motor .................
pinMode(MotorA1Pin,OUTPUT);
pinMode(MotorA2Pin,OUTPUT);
pinMode(MotorENAPin,OUTPUT);
//............ RIGHT Gear Motor ................
pinMode(MotorB1Pin,OUTPUT);
pinMode(MotorB2Pin,OUTPUT);
pinMode(MotorENBPin,OUTPUT);
//............ Enable Motors ...............
digitalWrite(MotorENAPin, HIGH);
digitalWrite(MotorENBPin, HIGH);
//............ Start IR receiver ............
irrecv.enableIRIn();
}
//
//............ Arduino Loop .................
//
void loop() {
//............ IR signal received ...........
if(irrecv.decode(&results))
{
//............ IR Input - 2 - Tank Motion _Forward
if(results.value==0xFD8877)
{
    motor(0,1,1,0);
}
//............ IR Input - 8 - Tank Motion_Backward
else if(results.value==0xFD9867)
{
    motor(1,0,0,1);
}
//............ IR Input - 4 - Tank Motion_Left
else if(results.value==0xFD28D7)
{
      motor(0,1,0,0);
}
//............ IR Input - 6 - Tank Motion_Right
else if(results.value==0xFD6897)
{
      motor(0,0,1,0);
}
//............ IR Input - 1 - Tank Motion_Fast Left
else if(results.value==0xFD08F7)
{
      motor(0,1,0,1);
}
//............ IR Input - 3 - Tank Motion_Fast Right
else if(results.value==0xFD48B7)
{
      motor(1,0,1,0);
}
//............ IR Input - 7 - Tank motion Right_backward
else if(results.value==0xFD18E7)
{
      motor(0,0,0,1);
}
//............ IR Input - 9 - Tank motion Left_backward
else if(results.value==0xFD58A7)
{
      motor(1,0,0,0);
}
//............ IR Input - 5 - Stop Motion
else if(results.value==0xFDA857)
{
      motor(0,0,0,0);
}
//............ IR Input - EQ - Turn on the LED
else if(results.value==0xFDB04F)
{
if (digitalRead(FrontLED)==HIGH)
{
digitalWrite(FrontLED,LOW);
}
else
{
  digitalWrite(FrontLED,HIGH);
}
}
//............ Receive the next value ...............
irrecv.resume();
//............ Short delay waiting for repeating IR signal
delay(300);
}
}
//
// Function to control the motor
// Non-return value subroutine
//
void motor(int MotorA1, int MotorA2, int MotorB1, int MotorB2) {
if (MotorA1==0) digitalWrite(MotorA1Pin,LOW);
if (MotorA2==0) digitalWrite(MotorA2Pin,LOW);
if (MotorB1==0) digitalWrite(MotorB1Pin,LOW);
if (MotorB2==0) digitalWrite(MotorB2Pin,LOW);
if (MotorA1==1) digitalWrite(MotorA1Pin,HIGH);
if (MotorA2==1) digitalWrite(MotorA2Pin,HIGH);
if (MotorB1==1) digitalWrite(MotorB1Pin,HIGH);
if (MotorB2==1) digitalWrite(MotorB2Pin,HIGH);
}
4  Using Arduino / Motors, Mechanics, and Power / I had a problem on L293D on: February 13, 2012, 01:04:45 pm
Dear

I had a problem on L293D.
I would like to make an IR remote tank which using the IR remote library from Ken Shirriff's blog.
When I send IR signal to arduino and turn on the motor, the motor turn on but arduino hang.
I had checked out several possible problems and finally I can get the control if I disable the L293D after delay a short while.
However, I would like the tank continous to run without stop.
I had some similar project did not need to disable the L293D for a while, so it really confuse me.
Could anybody suggest a reason for me ?


+++++++++ here is the code that I can get the control if I disable the L293D after delay a short while ++++++

void motor(int MotorA1, int MotorA2, int MotorB1, int MotorB2) {
digitalWrite(MotorENAPin, HIGH);
digitalWrite(MotorENBPin, HIGH);
if (MotorA1==0) digitalWrite(MotorA1Pin,LOW);
if (MotorA2==0) digitalWrite(MotorA2Pin,LOW);
if (MotorB1==0) digitalWrite(MotorB1Pin,LOW);
if (MotorB2==0) digitalWrite(MotorB2Pin,LOW);
if (MotorA1==1) digitalWrite(MotorA1Pin,HIGH);
if (MotorA2==1) digitalWrite(MotorA2Pin,HIGH);
if (MotorB1==1) digitalWrite(MotorB1Pin,HIGH);
if (MotorB2==1) digitalWrite(MotorB2Pin,HIGH);
delay(800);
digitalWrite(MotorENAPin, LOW);
digitalWrite(MotorENBPin, LOW);
}
5  Using Arduino / Motors, Mechanics, and Power / Re: Question about Servo library on: June 30, 2011, 02:22:15 am
Thx u very much.
6  Using Arduino / Motors, Mechanics, and Power / Question about Servo library on: June 29, 2011, 12:00:52 pm
I am confuse about  "servo.h" and "SoftwareServo.h"...
Would somebody help me to clarify them ?

First, someone said "servo.h" can only control 2 servo (Max) and it should be connected to pin 9 and 10, isn't it ?

Then "SoftwareServo.h" can control 13 servo (Max) for arduino duemilanove, isn't it ? (http://arduino.cc/playground/ComponentLib/Servo)
But it said that SoftwareServo.h will disable the PWM function of pin 9 and 10 (http://www.arduino.cc/en/Reference/Servo), so the library can or can't control a servo motion that connect to pin 9 and 10 ?

So, what is the different between "Servo.h" and "SoftwareServo.h" ?

Many Thx.
7  Using Arduino / Audio / Re: Drum sound on: June 10, 2011, 12:15:57 am
Thx, u really help me solve the problems.
I always think that I need to setup something on my MIDI keyboard,
however, the "DRUM" sketch itself is for DRUM MIDI.
As I modify the Channel from x90 to x99, I finally hear drum sound....

Many Thx.
8  Using Arduino / Audio / Drum sound on: June 09, 2011, 01:10:57 pm
I had download the code from this page
http://todbot.com/blog/2006/10/29/spooky-arduino-projects-4-and-musical-arduino/

Although the code said it play drum sound, when I connect Arduino with my CASIO CTK-6201, I can only hear piano sound...

Then, I get some demo code from internet, all I can hear is still piano sound....
I wonder it is the setup problem of the CASIO CTK-6201.

Could somebody give me some hints for it ? Is it a problem of GM of CASIO CTK-6201?
9  Using Arduino / General Electronics / Re: 595 can not count... with Video... on: June 09, 2011, 01:17:46 am
Thx to All....
I had worked out for several hours and did not solve the problem...
but finally, I had solved the problem.

The reset is due to the present of "Sony Ericsson PC Companion 2.0" in the system.
 smiley-kitty
10  Using Arduino / General Electronics / Re: 595 can not count... with Video... on: June 09, 2011, 01:01:19 am
I had connected

Arduino +5V -----------> 595 ----------- VCC (pin 16) + MR pin 10
Arduino GND -----------> 595 ----------- GND (pin 08)

Since it did not have flicking... I did not connect the 1uF capacitor...
11  Using Arduino / General Electronics / Re: 595 can not count... on: June 09, 2011, 12:46:35 am
Here is the video.



Please give some advices...
12  Using Arduino / General Electronics / Re: 595 can not count... on: June 09, 2011, 12:21:05 am
Yes, because I did not know much about 595...
13  Using Arduino / General Electronics / Re: 595 can not count... on: June 09, 2011, 12:19:52 am
I copy the code from
http://arduino.cc/en/Tutorial/ShftOut11
14  Using Arduino / General Electronics / 595 can not count... with Video... on: June 09, 2011, 12:17:52 am
I am using the Hello World program which something like 8-bit Counter.
http://www.arduino.cc/en/Tutorial/ShiftOut

The problem is, I found that the LED stop at the middle (ie. restart when counter to ~37)
However, when I add Serial.beign(9600) and start serial monitor the output at the same time.
The counter seems work normally....



I had tested various sample codes and still find the same problem, did I miss something important ?

Many Thx...
15  Using Arduino / General Electronics / Re: About TIP120 and IRF510 on: May 14, 2011, 09:22:57 am
Many Thx.
Pages: [1] 2