Show Posts
Pages: [1] 2
1  Using Arduino / Audio / Arduino controls an LM4832 Headphone Amp with I2C on: January 25, 2014, 02:39:23 pm
I'm building a Headphone AMP with Tone control using the LM4832. Cheap to buy on Ebay.
This way I can  have a better and Powerful sound than I can get direct out of my  IPad and/or  IPhone  smiley-razz

First test are looking good smiley

This Sketch should awaken the LM4832 and you can get a LED to Flash on the General output.
Download the Datasheet and you can control the other features of the LM4832 smiley



Quote
/*
HeadPhone Amp controlling LM4832
*/
 
 #include <Wire.h>                    // I2C Library
 
 byte LM4832Address = 0x80 >> 1;      // I2C bus address for LM4832 (pin 15 and 16 to GND)
 
 void setup()
 {  Serial.begin(9600);                   //
    Wire.begin();                         //
    // General control:
    Wire.beginTransmission(LM4832Address);
    Wire.write(B11100010);                            
    Wire.endTransmission();
    // Set volume in
    Wire.beginTransmission(LM4832Address);
    Wire.write(B00000010);                            
    Wire.endTransmission();
    // Set volume out LEFT:
    Wire.beginTransmission(LM4832Address);
    Wire.write(B10001001);                            
    Wire.endTransmission();
    // Set volume out RIGHT:
    Wire.beginTransmission(LM4832Address);
    Wire.write(B01101001);                            
    Wire.endTransmission();
        
    Serial.println("LM4832 Initialized!");}
 
 void loop()
 {  Serial.println("Running in loop");
    delay(500);
    // LED ON
    Wire.beginTransmission(LM4832Address);
    Wire.write(B11100010);                            
    Wire.endTransmission();
    delay (500);
    // LED OFF
    Wire.beginTransmission(LM4832Address);
    Wire.write(B11100000);                            
    Wire.endTransmission(); }
 
2  Using Arduino / Project Guidance / Re: Receive Pelco commands from cctv system, move servo's on: January 25, 2014, 02:07:25 pm
Made some improvements.

Now I can control trough Pelco commands a Sony Visca camera!
This is only the Part for reading the Pelco commands.

Quote
/*  
This program is used for an Arduino to receive and decode PELCO-D PTZ Commands

- Read Pelco-D commands 2400/4800/9600 Baud on software serial port
- Checksum calculation to prevent wrong decoding
- First Pelco Byte check (FF) to prefent wrong serial data is being read
- Transmit Visca commands on main serial port

Pelco-D Command:
outArray[0] = Byte 0 = Always FF
outArray[1] = Byte 1 = Camera Number
outArray[2] = Byte 2 = Control word 1
outArray[3] = Byte 3 = Control word 2
outArray[4] = Byte 4 = Data
outArray[5] = Byte 5 = Data
outArray[6] = Byte 6 = Checksum

 */

#include <LiquidCrystal.h>     // LCD
#include <SoftwareSerial.h>    // Software serial port

#define rxPin 2                // second software serial port RX on pin 2 and TX on pin 4
#define txPin 4

  SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);   // activate software serial port

  LiquidCrystal lcd(12, 11, 9, 8, 7, 6);  // connect to 4 Bit LCD screen

  byte outArray[7];        // Serial buffer
  int stopcheck;           // For checking when a STOP command is received (0)
  int checksum;            // For Calculating Checksum. Sum of the payload bytes (bytes 2 through 6) in the message
  int ByteNumber;          // Counter for reading the serial buffer
 
void setup(){
  
  lcd.begin(16, 2);        // set up the LCD's number of columns and rows:
  lcd.setCursor(0,0);
  lcd.print("Ready");

 
  Serial.begin(9600);      // Visca Baudrate 9600
  mySerial.begin(9600);    // Pelco baud rate  9600 can be 1200,2400 or 4800

}

void loop()
{
  if ( mySerial.available () > 0) {
     outArray[ByteNumber ++] = mySerial.read();
  if ( outArray[0] != 0xFF ) { ByteNumber = 0;}}   // When Byte 0 isn't 0xFF (Pelco 1st Byte) reset Bytenumber to 0 preventing the serial port being blocked.
  
  if ( ByteNumber > 6){                 // process it
       ByteNumber = 0;                  // ready for next time
      
       checksum =  outArray[1] + outArray[2] + outArray[3] + outArray[4] + outArray[5]  ;  // calculate checksum
 
  if ( checksum == outArray[6]) {       // Procces data only when the checksum is valid
 
       stopcheck =  outArray[2] + outArray[3] + outArray[4] + outArray[5] ;   // Calculate if STOP Command is received
  if ( stopcheck == 0){                 // When stopcheck is 0 a STOP command is received
       StopActions();}                  // Stop all PTZ Actions
    
 else{ printCommand();}                 // Print Pelco command on LCD
 
  if ( bitRead(outArray[3],0) == 0 ){   // When BIT 0 = 0 command 2 than data is Normal command (PTZ)
       Decoding();}                     // Try to decode the Pelco Command

  if ( bitRead(outArray[3],0) == 1 ){   // When BIT 0 = 1 command 2 than data is an Extended command
       ExtendedCommands();}             // Try to decode the Extended Pelco Command
}  // proces when checksum is Ok    
}  // end if buffer full
}  // end of loop

3  Using Arduino / Programming Questions / Re: What is the Arduino Uno Serial buffer size? on: January 11, 2014, 11:30:02 am
GOOD NEWS!!!!
I got it working!

Hi Michael,

Thanks to your program I managed to receive serial PELCO commands. These commands are used to control
CCTV camera systems.  smiley

http://forum.arduino.cc/index.php?PHPSESSID=bhv3n6da4s1f2a8d0b3ip2er66&topic=155693.0
4  Using Arduino / Project Guidance / Re: Receive Pelco commands from cctv system, move servo's on: January 11, 2014, 11:05:11 am
@gazz

Did you find any way to decode Pelco Commands?

I managed to decode Pelco D commands

Used this information:
http://cvs.ru/files/pelco-d.pdf
http://forum.arduino.cc/index.php?topic=96280.0
http://www.commfront.com/RS232_Examples/CCTV/Pelco_D_Pelco_P_Examples_Tutorial.HTM
http://www.serialporttool.com/

I'm not finished yet to control all  the hardware but I can read all the commands if I want to smiley
I use the Checksum to be sure  wrong received commands are ignored.
Just finished testing to control the PAN speed. Use PWM to set the right speed.
Not happy with it. Searching for another way to control the motor speed. With light (low current) motors it works Ok.

For recieving RS-485 commands I use a MAX485 IC. For testing you can use the serial comport of the Ardiuno.




Quote
/*  
 This program is used for an Arduino to receive and decode PELCO-D PTZ Commands
 
 Thanks to Michael Blaylock for his sketch.  Learning how to read and procces serial data
 
 */

#include <LiquidCrystal.h>

  LiquidCrystal lcd(12, 11, 9, 8, 7, 6);

  byte outArray[7];        // read data Pelco Command
  unsigned stopcheck;      // For checking when a STOP command is received (257 Decimal)
  int checksum;            // For Calculating Checksum. Sum of the payload bytes (bytes 2 through 6) in the message
  int ByteNumber;
  int MotorSpeed;

void setup(){
  
  lcd.begin(16, 2);        // set up the LCD's number of columns and rows:

  Serial.begin(9600);      // baud rate  9600 can be 1200,2400 or 4800

  pinMode(3,  OUTPUT);
  pinMode(5,  OUTPUT);
  pinMode(13, OUTPUT);

  digitalWrite(3, HIGH);
  digitalWrite(5, HIGH);

}

void displayData()          // Display the array in serial monitor for debugging
{
  for (int j = 0; j<7; j+=1){
  Serial.println(outArray[j],HEX);}
  Serial.println("Data Printed");}

void loop()
{
  if ( Serial.available () > 0) {
       outArray[ByteNumber ++] = Serial.read();}
  
  if ( ByteNumber > 6){         // process it
       ByteNumber = 0;          // ready for next time
 //    displayData();           // for debugging
 
       stopcheck = outArray[0] + outArray[1] + outArray[2] + outArray[3] + outArray[4] + outArray[5] + outArray[6] ;   // Calculate if STOP Command is received
  if ( stopcheck == 257){       // When stopcheck is 257 decimal a STOP command is received
       StopActions();}          // Stop all PTZ Actions
    
 else{ printCommand();}         // Print Pelco command on LCD
 
  if ( bitRead(outArray[3],0) == 0 ){   // When BIT 0 = 0 command 2 than data is Normal command (PTZ)
       Decoderen();}                    // Try to decode the Pelco Command

  if ( bitRead(outArray[3],0) == 1 ){   // When BIT 0 = 1 command 2 than data is an Extended command
       ExtendedCommands();}             // Try to decode the Extended Pelco Command
    
}  // end if full
}  // end of loop


void Decoderen()
{
 
 lcd.setCursor(0,1);
 
      MotorSpeed = map (outArray[4],  0, 0x3F, 255, 0);
 // PAN TILT:
  if ( bitRead(outArray[3],1) == 1 ){
      analogWrite(3 , MotorSpeed);
      // digitalWrite(3, HIGH);
      lcd.print("RIGHT SPEED: ");
      lcd.print(outArray[4]);}
  
  if ( bitRead(outArray[3],2) == 1 ){
      analogWrite(5, MotorSpeed);  
      // digitalWrite(5, HIGH);
      lcd.print("LEFT  SPEED: ");
      lcd.print(outArray[4]);}
  
  if ( bitRead(outArray[3],3) == 1 ){
      lcd.print("UP    SPEED: ");
      lcd.print(outArray[5]);}
  
  if ( bitRead(outArray[3],4) == 1 ){
      lcd.print("DOWN  SPEED: ");
      lcd.print(outArray[5]);}
  
 // ZOOM IRIS FOCUS:
  if ( bitRead(outArray[2],2) == 1 ){
      lcd.print("Iris Close");}
  if ( bitRead(outArray[2],1) == 1 ){
      lcd.print("Iris Open");}
  if ( bitRead(outArray[2],0) == 1 ){
      lcd.print("Focus Near");}
  if ( bitRead(outArray[3],7) == 1 ){
      lcd.print("Focus Far ");}
  if ( bitRead(outArray[3],6) == 1 ){
      lcd.print("Zoom Wide ");}
  if ( bitRead(outArray[3],5) == 1 ){
      lcd.print("Zoom Tele ");}  
  
}

void ExtendedCommands()
{
  
     lcd.setCursor(0,1);

  if ( outArray[2] == 0 ){         // Only continu when Word 3 is 0
 
  if ( outArray[3] == 0x03 ){      // SET PRESET      
     lcd.print("Set Preset: ");
     lcd.print(outArray[5]-1);}    // PRINT Preset. -1 to calculate right preset
  
  if ( outArray[3] == 0x05 ){      // Clear Preset    
     lcd.print("Clear Preset:");
     lcd.print(outArray[5]-1);}    // PRINT Preset. -1 to calculate right preset
          
}}



5  Using Arduino / Networking, Protocols, and Devices / ENC28j60 webserver from SD card on: October 29, 2012, 03:06:21 pm
I found a code to use the ethershield to run the website stored on the SD card.
It works fine with the original v5 5100 ethershield i have.
Code found at topic: http://arduino.cc/forum/index.php?topic=100360.0

When I connect the ENC28j60 and a SD card and the CS pins simulair as the ethershield it doesn't work.
I use the enc library.

The index file is read by the browser then nothing happens.
After a while the browser repports error 404 send from the arduino.

Sketches only using the SD  or  Ethernet are working fine.

Using software 22. Checked al the setting of the CS ports.
Using arduino mega 1280.
Pin 53 CS ethernet. Pin 10 still setup as output high.
Pin 4 CS SD card

Is it possible to use the Enc ethernet this way?
Has someone a working code?

Many thanks.

SH
6  Using Arduino / Displays / Re: How to use Underline I2C 16x2 KS0066F00 on: February 07, 2012, 01:32:02 am
Quote
I want to use the available underline as a progress bar.
I think you are confusing the 'underline' with the cursor.  You use the set.cursor() function to determine where to display the character.  You then have to display the character itself which would be done with Serial.print('_') .

Don

Sorry I used lcd.cursor.  I attached a picture. Here you can see the cursor. I want to use the cursor at more the one spot.

Maybe I can do something with createChar().

thanks
7  Using Arduino / Displays / How to use Underline I2C 16x2 KS0066F00 on: February 06, 2012, 07:59:25 am
I'm using a 16x2 Samsung KS0066F00 display.
I want to use the available underline as a progress bar.
I can access the row with set.cursor but only on one spot.
Does anybody knows a way to do this?

Thanks.

SH
8  Using Arduino / Networking, Protocols, and Devices / Re: I2C Distance on: April 07, 2011, 04:24:12 am
I use the P82B715PN with about 20meter Cat-5 UTP cable. Works fine. smiley
9  Using Arduino / Networking, Protocols, and Devices / Re: I2C Distance on: April 06, 2011, 07:36:49 am
I used P82B715PN I2C extender IC from Philips.  Very cheap and easy:

http://pdf1.alldatasheet.com/datasheet-pdf/view/15876/PHILIPS/P82B715PN.html
10  Using Arduino / Project Guidance / Re: Set/Change IP Address Web Form - Ethernet Shield on: April 06, 2011, 07:21:37 am
Quote
byte mac[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Do you have multiple Arduino's with the same MAC address? if so change them asap as they should be unique,

just a thought.

Sorry No just one. smiley-confuse

I found out that the program always jumps to void mkmethernetRESET().
Because I haven't set a new IP address the EEprom values are wrong.
I forced the program to jump to void mkmethernetDEFAULTS().
Now I get only a blank page and I can ping the Arduino.


11  Using Arduino / Project Guidance / Re: Set/Change IP Address Web Form - Ethernet Shield on: April 06, 2011, 06:48:53 am
The revised web form code is now working properly (for me at least), see attachments.

To bad it doesn't work on my Uno and latest ethershield (microSD reader).
Can't ping the IP adres.

If I Disabling these settings I can ping the arduino but can't access the webpages:

  //EEPROM address to  array
//  byte mac[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//  byte ip[4] = { ipAaddress_READ, ipBaddress_READ, ipCaddress_READ, ipDaddress_READ };
//  byte gateway[4] = { gwAaddress_READ, gwBaddress_READ, gwCaddress_READ, gwDaddress_READ };   
// byte subnet[4] = { subnetAaddress_READ, subnetBaddress_READ, subnetCaddress_READ, subnetDaddress_READ };   
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: IF ¬†with AND and OR fuctions on: December 02, 2010, 02:20:55 pm
Quote

Thanks for this link didn't now where to look.

It works perfect now. Many thanks smiley smiley smiley
13  Forum 2005-2010 (read only) / Syntax & Programs / IF  with AND and OR fuctions on: December 02, 2010, 11:02:58 am
With my BASIC language programmed controllers I can use AND and OR.

example:  IF (VAL > 100 AND VAL < 140) THEN ...

How can I solve this with the if function in the Arduino?

Thanks.  smiley-wink
14  Forum 2005-2010 (read only) / Development / Re: Arduino-izing the AVR Butterfly on: October 28, 2010, 12:54:01 pm
Thanks.
I have a butterfly laying around on my desk for quite a while maybe now  I can do some funny stuff with it.  smiley

15  Forum 2005-2010 (read only) / Development / Re: Arduino-izing the AVR Butterfly on: October 28, 2010, 06:54:32 am
fortunality all the links to the arduino012_butterfly.zip file are broken.
Where can I download this file or can someone email the file (email button)

Thanks  smiley-wink
Pages: [1] 2