6/03/2014

Explain Arduino Mega 2560 R3 pins

Arduino Mega 2560
                      
      




Input and Output

Each of the 54 digital pins on the Arduino 2560 Mega can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms.



In addition, some pins have specialized functions:
Serial: 0 (RX) and 1 (TX);
Serial 1: 19 (RX) and 18 (TX);
Serial 2: 17 (RX) and 16 (TX);
Serial 3: 15 (RX) and 14 (TX).
Used to receive (RX) and transmit (TX) TTL serial data. Pins 0 and 1 are also connected to the corresponding pins of the ATmega16U2 USB-to-TTL Serial chip.
External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite() function.
SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI communication using the SPI library. The SPI pins are also broken out on the ICSP header, which is physically compatible with the Uno, Duemilanove and Diecimila.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it’s off.
TWI: 20 (SDA) and 21 (SCL). Support TWI communication using the Wire library. Note that these pins are not in the same location as the TWI pins on the Duemilanove or Diecimila.
The Mega2560 has 16 analog inputs, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and analogReference() function.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board.

5/25/2014

UIPEthernet EchoServer example and test


Below example code. from UIPEthernet library.



/*
 * UIPEthernet EchoServer example.
 *
 * UIPEthernet is a TCP/IP stack that can be used with a enc28j60 based
 * Ethernet-shield.
 *
 * UIPEthernet uses the fine uIP stack by Adam Dunkels <adam@sics.se>
 *
 *      -----------------
 *
 * This Hello World example sets up a server at 192.168.1.6 on port 1000.
 * Telnet here to access the service.  The uIP stack will also respond to
 * pings to test if you have successfully established a TCP connection to
 * the Arduino.
 *
 * This example was based upon uIP hello-world by Adam Dunkels <adam@sics.se>
 * Ported to the Arduino IDE by Adam Nielsen <malvineous@shikadi.net>
 * Adaption to Enc28J60 by Norbert Truchsess <norbert.truchsess@t-online.de>
 */

#include
// The connection_data struct needs to be defined in an external file.
#include
#include


EthernetServer server = EthernetServer(1000);

void setup()
{
  Serial.begin(9600);
  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
  IPAddress myIP(192,168,1,177);
  Ethernet.begin(mac,myIP);
  server.begin();
}
void loop()
{
  size_t size;
  if (EthernetClient client = server.available())
    {
      if (client)
        {
          while((size = client.available()) > 0)
            {
              uint8_t* msg = (uint8_t*)malloc(size);
              size = client.read(msg,size);
              Serial.write(msg,size);
              client.write(msg,size);
              free(msg);
            }
        }
    }
}


Testing.

$ telnet 192.168.1.177 1000
Trying 192.168.1.177...
Connected to 192.168.1.177.
Escape character is '^]'.

( typing keyboard ... for test )



5/24/2014

Arduino pro mini 3.3v 8MHz or 5V 16 MHz - ENC28J60 SPI wire pin map.



ENC28J60 SPI

Arduino pro mini 3.3v - VCC no ohm.

Arduino pro mini 5v = VCC 10 ohm 



Mini Ethernet Module Arduino Pro Mini
GND GND
3.3V 3.3V ( 250 mA, VDD = 3.45V, FCLK =10 MHz, SO = open )  
RESET not connected  - or connect.
CLKOUT not connected
INT PIN 3
W0L not connected
S0 PIN 12
SI PIN 11
SCK PIN 13
CS PIN 8 or PIN 10    
--- ---

5/20/2014

Ubuntu, Raspberry Pi,CubieBoard Linux A2DP, bluetooth audio source receiver service, speaker


Bluetooth A2DP receiver.

$ sudo apt-get install pulseaudio-module-bluetooth
$ pactl load-module module-loopback source_dont_move=yes source=$BTSOURCE sink=$SINK
  • You can find $SINK with $ pactl list sinks, $SINK is shown after Name:
  • And you can see the $BTSOURCE with $ pactl list sources
$ pactl load-module module-loopback source_dont_move=yes source=bluez_source.9C_E6_E7_C8_B2_A3 sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
ex) Play audio from Smartphone 

Find pulseaudio source list
 $ pactl list sources
Source #0
        State: IDLE
        Name: alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor
        Description: Monitor of bcm2835 ALSA Analog Stereo
        Driver: module-alsa-card.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 4
        Mute: no
        Volume: 0: 100% 1: 100%
                0: 0.00 dB 1: 0.00 dB
                balance 0.00
        Base Volume: 100%
                     0.00 dB
        Monitor of Sink: alsa_output.platform-bcm2835_AUD0.0.analog-stereo
        Latency: 0 usec, configured 371519 usec
        Flags: DECIBEL_VOLUME LATENCY 
        Properties:
                device.description = "Monitor of bcm2835 ALSA Analog Stereo"
                device.class = "monitor"
                alsa.card = "0"
                alsa.card_name = "bcm2835 ALSA"
                alsa.long_card_name = "bcm2835 ALSA"
                alsa.driver_name = "snd_bcm2835"
                device.bus_path = "platform-bcm2835_AUD0.0"
                sysfs.path = "/devices/platform/bcm2835_AUD0.0/sound/card0"
                device.string = "0"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card"
        Formats:
                pcm

Source #2
        State: RUNNING
        Name: bluez_source.9C_E6_E7_C8_B2_A3
        Description: SHW-M440S
        Driver: module-bluetooth-device.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 25
        Mute: no
        Volume: 0: 100% 1: 100%
                0: 0.00 dB 1: 0.00 dB
                balance 0.00
        Base Volume: 100%
                     0.00 dB
        Monitor of Sink: n/a
        Latency: 198393 usec, configured 193344 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY 
        Properties:
                bluetooth.protocol = "a2dp_source"
                device.description = "SHW-M440S"
                device.string = "9C:E6:E7:C8:B2:A3"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                bluez.path = "/org/bluez/2163/hci0/dev_9C_E6_E7_C8_B2_A3"
                bluez.class = "0x5a020c"
                bluez.name = "SHW-M440S"
                device.icon_name = "audio-card-bluetooth"
        Formats:
                pcm

Arduino pro mini 5v 3.3 v - bootloader, write AVR MKII



Arduino pro mini bootloader write AVR MKII

- Avr Studio 4.18

- Attached avr mkii on Win7 64.

AVR MKII driver install.  ( not libusb driver )


 Your Installed Dir Arduino Sketch \
                            Arduino\
                            arduino-1.5.6-r2-windows\
                            arduino-1.5.6-r2\
                            hardware\
                            arduino\
                            avr\
                            bootloaders


Boot Loader Hex file Pro mini 5V/16MHz

reference from boards.txt ( arduino-1.5.6-r2-windows\arduino-1.5.6-r2\hardware\arduino\avr )

pro.menu.cpu.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex