Tuesday, December 30, 2014

Arduino USB Control with Firmata




Control RGB LEDs ( Arduino Uno )



Arduino USB Control with Firmata Library

Arduino Firmata Library is source code to communicate or control Arduino Board with other device.

Firmata is already include in your Arduino IDE.




Firmata Test Program
This "firmata_test" program works with boards running StandardFirmata version 2.2 or higher on standard Baud rate 57600.

For Linux (32 bit)

For Linux (64 bit)

For Mac OS-X

For Windows

Source code
http://www.pjrc.com/teensy/firmata_test/firmata_test_OSL.tgz (unicode compatible, by Orion Lawlor)




We Test on Windows ( see VDO above )

First Program Firmata Code to Arduino Board.

Open Arduino IDE ( we use Arduino 1.0.6 )


Goto File > Examples > Firmata > StandardFirmata




Then Upload to your Arduino Board



Open Firmata Test Program ( we test on Windows )



Connect USB to your Arduino Board then Select port.




Ready To Control




Android USB Control with Firmata







Firmata Command


Methods


begin()
start the library
begin(long)
start the library and override the default baud rate
printVersion()
send the protocol version to the host computer
blinkVersion()
blink the protocol version on pin 13
printFirmwareVersion()
send the firmware name and version to the host computer
setFirmwareVersion(byte major, byte minor)
set the firmware name and version, using the sketch's filename, minus the .pde

Sending Messages

sendAnalog(byte pin, int value)
send an analog message
sendDigitalPorts(byte pin, byte firstPort, byte secondPort)
send digital ports as individual bytes
sendDigitalPortPair(byte pin, int value)
send digital ports as one int
sendSysex(byte command, byte bytec, byte* bytev)
send a command with an arbitrary array of bytes
sendString(const char* string)
send a string to the host computer
sendString(byte command, const char* string)
send a string to the host computer using a custom command type

Receiving Messages

available()
check to see if there are any incoming messages in the buffer
processInput()
process incoming messages from the buffer, sending the data to any registered callback functions
attach(byte command, callbackFunction myFunction)
attach a function to an incoming message type
detach(byte command)
detach a function from an incoming message type

Callback Functions

In order to attach your function to a message type, your function must match the standard callback function. There are currently three types of callback functions in Firmata: generic, string, and sysex.
generic
void callbackFunction(byte pin, int value);
system_reset
void systemResetCallbackFunction(void);
string
void stringCallbackFunction(char *myString);
sysex
void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);

Message Types

These are the various message types that you can attach functions to.
ANALOG_MESSAGE
the analog value for a single pin
DIGITAL_MESSAGE
8-bits of digital pin data (one port)
REPORT_ANALOG
enable/disable the reporting of analog pin
REPORT_DIGITAL
enable/disable the reporting of a digital port
SET_PIN_MODE
change the pin mode between INPUT/OUTPUT/PWM/etc.
FIRMATA_STRING
C-style strings, uses stringCallbackFunction for the function type
SYSEX_START
generic, arbitrary length messages (via MIDI SysEx protocol), uses sysexCallbackFunction for the function type
SYSTEM_RESET

message to reset firmware to its default state, uses systemResetCallbackFunction for the function type


My Website
http://softpowergroup.net/
email : info@softpowergroup.net   Tel .081-6452400
Google+  https://plus.google.com/+SoftpowergroupNetThailand/

Wednesday, November 19, 2014

Arduino and 128x64 GLCD




Arduino and 128x64 Graphic LCD

Hardware

1.Arduino Board
2.128x64 Graphic LCD Module (controller  KS0108 Chip or Equivalent ) ST7920  SBN6400G , SBN0064G


We use this model http://www.es.co.th/detail.asp?Prod=13502884 from Electronic Source Thailand


Data Sheet http://www.es.co.th/Schemetic/PDF/LCD128G064A.PDF



Wiring Diagram



 GLCD Pinout



Add VR10K to adjust Brightness.




Connect to Arduino



For Arduino Mega
Arduino Pin 22   for  D7
Arduino Pin 23   for  D6
Arduino Pin 24   for  D5
Arduino Pin 25   for  D4
Arduino Pin 26   for  D3
Arduino Pin 27   for  D2
Arduino Pin 28   for  D1
Arduino Pin 29   for  D0
Arduino Pin 33   for  CS1
Arduino Pin 34   for  CS2
Arduino Pin 35   for R/W
Arduino Pin 36   for  RS
Arduino Pin 37   for  EN

Arduino Pin 13  for LCD Back Light Control



Software ( Arduino Library )



Arduino GLCD Library Version3 ( or AVR Controller )

Download https://code.google.com/p/glcd-arduino/downloads/list



GLCD-Arduino has the following features:
  • Support for Arduino 1.x (still works with pre 1.x IDEs)
  • Support for Mega 2560, Sanguino and Teensy boards
  • Easier pin assignment. Any pin can be assigned to any glcd function.
  • Accurate/Consistent font rendering of any font size on any pixel location.
  • User definable text areas
  • Up/Down text scrolling
  • Circle functions
  • Additional example and demo sketches including a diagnostic sketch
  • Fully search-able documentation in HTML format
  • Pins can optionally be assigned by AVR port and bit instead of Arduino pin number.
  • Supports fixed width fonts that provides up to 8 x 21 character display with the supplied system font.
  • CursorTo method to position the cursor to a given font location (fixed width fonts only)
  • DrawBitmap function to display bitmap images stored in Flash memory. A Processing utility is provided in the download to convert a monochrome bitmap file to a header file that stores the image in flash for use by the DrwBitmap method.


Create Font  use GLCD Font Creator 2
Use this program https://code.google.com/p/glcd-arduino/downloads/detail?name=GLCDFontCreator2.zip



How to Create Font in other Language


FONT 8 x 8

FONT 14 x 20


Example in Thai language
I've edit GLCD Font Creator 2 for Thai language only. ( Java Code )






My Website
http://softpowergroup.net/
email : info@softpowergroup.net   Tel .081-6452400
Google+  https://plus.google.com/+SoftpowergroupNetThailand/

Monday, November 3, 2014

Arduino and TFT LCD Display Module



Arduino TFT LCD Display Module Test

Hardware
1.Arduino UNO Board or Compatible
2.TFT LCD 2.2 inch  from Elecfreaks ( Model  TFT01-2.2SP )
http://www.elecfreaks.com/store/22%E2%80%99-tft-lcd-tft0122sp-p-672.html


Description:

TFT LCD module has always been one of the hot products in DIY industry and LCD is basically the necessary products during all projects, at the same time, serial port modules are also the popular ones, because it takes few IO and the usage is simple. This section of the 2.2S-inch TFT LCD serial SPI integrated features of compact, SPI interface, fully compatible with popular LCD5110 interface cable sequence, and will replace the increasingly reducing LCD5110.

Feature:

TFT01_2.2 SP is a 2.2 "SPI TFT LCD Screen Module, 10pins interface, compatible LCD5110 interface. Not just a LCD break but include SD card (2GB),
The LCD in the TFT01 is ILI9341. It's a 240 * 320 (resolution), 2.2S inch TFT LCD screen.The LCD has a wide viewing angle, the contrast is also very suitable.

The display interface is serial, it just needs 5 wires (CS, RS, SCL, SDA, RST) for controlling.
Replace LCD5110, Support direct plug in ElecFreaks Joystick shield, EFCom, Key Pad Shield etc
SDcard use hardware SPI interface (CS / MOSI / MISO / SCK), Not solder pins.
Parameter:

SDO: Serial clock output
LED: 3.3V IO and Power Supply pin
SCL: Serial clock input
SDA / SDI: Serial data input
DC: Data / Command selection
RST: Reset, Low level active
CS: Chip Selection, Low level active
GND: Ground
VDD33: 3.3V Power Supply pin
UTFT Support


Wiring Diagram





TFT Pin SDO<MISO>     Not Used

TFT Pin LED                   To  VCC 3.3V

TFT Pin SDI<MOSI>      To Arduino PIN D9

TFT Pin SCK                   To Arduino PIN D8

TFT Pin D/C                    To Arduino PIN D10

TFT Pin RESET              To Arduino PIN D11

TFT Pin CS                      To Arduino PIN D12

TFT Pin GND                  To Arduino PIN GND

TFT Pin VCC                  To Arduino PIN 3V3


Software

Driver UTFT Library  by Henning Karlsen
http://henningkarlsen.com/electronics/library.php?id=52

his library is the continuation of my ITDB02_Graph, ITDB02_Graph16 and RGB_GLCD libraries for Arduino and chipKit. As the number of supported display modules and controllers started to increase I felt it was time to make a single, universal library as it will be much easier to maintain in the future.


Download Source code



My Website
http://softpowergroup.net/
email : info@softpowergroup.net   Tel .081-6452400
Google+  https://plus.google.com/+SoftpowergroupNetThailand/

Monday, January 20, 2014

Arduino USB Control Servo Motor



Arduino USB Control Servo Motor

Use Arduino Board to control Servo Motor.

Hardware

1. Arduino Board or compatible Board.

2. USB Cable ( A to B Male/Male )

3. Servo Motor ( We use FUTABA Model S3003 or other)

Wiring Diagram
Use Arduino PWM Output pin 9


Arduino Code  Download code Link
 #include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position
int motor = 0;

void setup()
{  
  Serial.begin(9600);  // initialize serial: 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 
  Serial.print("Arduino control Servo Motor Connected OK");
  Serial.print('\n');
}

void loop()
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    
    // look for the next valid integer in the incoming serial stream:
    motor = Serial.parseInt();
   
    // do it again:
    pos = Serial.parseInt();
  
    // look for the newline. That's the end of your  sentence:
    if (Serial.read() == '\n') {
              
       myservo.write(pos);              // tell servo to go to position in variable 'pos'
       delay(15);                       // waits 15ms for the servo to reach the position
     
      // print the three numbers in one string as hexadecimal:
      Serial.print("Data Response : ");
      Serial.print(motor, DEC);
      Serial.print(pos, DEC);
      
    }
  }
}
 
  //for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  //{                                  // in steps of 1 degree
  //  myservo.write(pos);              // tell servo to go to position in variable 'pos'
  //  delay(15);                       // waits 15ms for the servo to reach the position
  //}
  //for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  //{                                
  //  myservo.write(pos);              // tell servo to go to position in variable 'pos'
  //  delay(15);                       // waits 15ms for the servo to reach the position
  //}
 
 
  //val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  //val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  //myservo.write(val);                  // sets the servo position according to the scaled value
  //delay(15);


Program Arduino Code to Arduino Board

Video :  How to upload Arduino Code


Open Arduino Program.


File Menu - Open



Select ServoControl.ino code


Verify code


Upload to Arduino Board

Command Control Testing

Command Control   a,bbb < Enter>  (a = Servo Motor = 1  , bbb = degree = 0-180 )

If you to control position to 90 degree.
Sent 1,90 <Enter>  to Arduino Board.

Use Tools - Serial Monitor on Arduino Program.
Tools - Serial Monitor



If connect to Arduino Board. 
Serial Monitor response "Arduino control Servo Motor Connected OK"





Sent Command   1,90 <Enter>  to set Servo Position to 90 degree.

Data Response : 15A 


Use Android + Arduino controls Servo Motor
http://androidcontrol.blogspot.com/2014/01/arduino-servo-motor-control.html