Categories

Arduino TouchKeyUSB shield example

The latest shield that has come into my posession is called the TouchKeyUSB shield, it looks a bit like this

touchkeyshield

Here is a description of its usage

Simulating a keyboard by microcontroller, leads a few keys, and using the touch form instead of switches. Now we can also use an Arduino board and a touch key USB shield to achieve this effect.

The input method of touch key USB shield is touch, using dual contacts touch switch, to lead the touch terminal and the ground terminal connected to the two electrodes touch. When human touch the two pole, because of the body resistance, a touch electrode between the two current flows, by detecting this current size of the touch event can be detected.

Basically you need to attach a crocodile clip or similar to the GND, you then connect  crocodile clips or similar to the terminals marked from A0 to A5. You then attach the other end of the AO to A5 crocodile clips to a coin. When you have uploaded the test sketch below and touch the GND and the coin an LED on the shield lights. At its most basic you are basically putting a high resistance (you) between one of the analog pins and GND.

 

Code

This is the code example I tested with – download link for the library and examples

As you can see the USB keyboard usage is commented out, you are supposed to be able to send keystrokes to a PC with this

// #include "UsbKeyboard.h"
int InData1 = 0, InData2 = 0, InData3 = 0, InData4 = 0, InData5 = 0, InData0 = 0;
int TouchSensitivity = 30;
void setup()
{
  for(int i = A0; i <= A5; i++)
    {
      pinMode(i, INPUT);
    }
 
  for(int i = 6; i <= 12; i++)
    {
      pinMode(i, OUTPUT); 
    }
 
  TIMSK0 &= !(1 << TOIE0);
}
 
void loop()
{
//  UsbKeyboard.update();
  InData0 = 1024 - analogRead(A0);                
  InData1 = 1024 - analogRead(A1);
  InData2 = 1024 - analogRead(A2);
  InData3 = 1024 - analogRead(A3);
  InData4 = 1024 - analogRead(A4);
  InData5 = 1024 - analogRead(A5);
 
  if(InData0 >= TouchSensitivity)
   {
    digitalWrite(6, HIGH);             
//    UsbKeyboard.sendKeyStroke(79); //right
   }
   else digitalWrite(6, LOW);
 
  if(InData1 >= TouchSensitivity)
   {
    digitalWrite(7, HIGH); 
//    UsbKeyboard.sendKeyStroke(80);  //left
   }
     else digitalWrite(7, LOW);
 
  if(InData2 >= TouchSensitivity)
   {
    digitalWrite(8, HIGH); 
//    UsbKeyboard.sendKeyStroke(81);  //down
   }
     else digitalWrite(8, LOW);
 
  if(InData3 >= TouchSensitivity)
   {
    digitalWrite(9, HIGH); 
//    UsbKeyboard.sendKeyStroke(82);  //up
   }
     else digitalWrite(9, LOW);
 
  if(InData4 >= TouchSensitivity)
   {
    digitalWrite(10, HIGH); 
//    UsbKeyboard.sendKeyStroke(KEY_SPACE);
   }
      else digitalWrite(10, LOW);
 
  if(InData5 >= TouchSensitivity)
   {
    digitalWrite(11, HIGH); 
//    UsbKeyboard.sendKeyStroke(KEY_ENTER);
   }
      else digitalWrite(11, LOW);
  delay(100);
}

 

Links

 
New Makey Makey touch key USB shield analog touch keyboard for arduino

FacebookTwitterGoogle+TumblrStumbleUponRedditLinkedInWhatsAppPinterestBaiduBufferDeliciousDiigoDiggOdnoklassnikiSina WeiboWordPressBlogger PostEmailShare

TSL2561 Luminosity Sensor example

This TSL2561 is an I2C light-to-digital converter TSL2561 that transforms light intensity to a digital signal. The TSL2561 features a selectable light spectrum range due to its dual light sensitive diodes: infrared and full spectrum. You can switch among three detection modes to take your readings. They are infrared mode, full spectrum and human visible mode.

When running under the human visible mode, this sensor will give you readings just close to your eye feelings.

Features

Selectable detection modes
High resolution 16-Bit digital output at 400 kHz I2C Fast-Mode
Wide dynamic range: 0.1 – 40,000 LUX
Wide operating temperature range: -40°C to 85°C
Programmable interrupt function with User-Defined Upper and lower threshold settings

Here is a typical module that makes it easier to work with the sensor

tsl2561

Layout and Connection

Device Pin Arduino
GND GND
Vcc / 3.3 (or Vin on Adafruit modules) 3.3 or 5v
SCL D1
SDA D2
ADDR N/C
Int N/C

 

 
Code

We use the Adafruit TS2561 library – this is a cut down version of the default – https://github.com/adafruit/Adafruit_TSL2561

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
 
 
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
 
 
void configureSensor(void)
{
  tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
}
 
 
void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Light Sensor Test"); 
  Serial.println("");
 
  /* Initialise the sensor */
  if(!tsl.begin())
  {
    Serial.print("no TSL2561 detected!");
    while(1);
  }
 
  configureSensor();
 
}
 
 
void loop(void) 
{  
  /* Get a new sensor event */ 
  sensors_event_t event;
  tsl.getEvent(&event);
 
  /* Display the results (light is measured in lux) */
  if (event.light)
  {
    Serial.print(event.light); 
    Serial.println(" lux");
  }
  else
  {
    Serial.println("Sensor overload");
  }
  delay(500);
}

Testing

Open the serial monitor window, mover the sensor to light sources, cover the sensor. you can see in the example below me moving to a bright light source and the value increasing

349.00 lux
757.00 lux
892.00 lux
992.00 lux
1192.00 lux
1890.00 lux
3324.00 lux
4051.00 lux
2708.00 lux
314.00 lux
128.00 lux
105.00 lux
112.00 lux
108.00 lux

Links

FacebookTwitterGoogle+TumblrStumbleUponRedditLinkedInWhatsAppPinterestBaiduBufferDeliciousDiigoDiggOdnoklassnikiSina WeiboWordPressBlogger PostEmailShare

Arduino LSM303 example

The LSM303 3D Accelerometers/Magnetometer Models are a system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor. These best-in-class eCompass devices enable superior PDR or unique use cases in emerging applications, including drones and personal navigation systems.

All full-scales available are fully selectable by the user. The device includes an I2C serial bus interface that supports standard and fast mode 100kHz and 400kHz.

Features

  • ST is enabling more accurate personal navigation and tracking for fitness and similar apps, with a new all-in-one eCompass IC
  • Advanced magnetic-sensing and MEMS technologies enable benchmark accuracy, with superior stability, power-saving and integration
  • 3 magnetic field channels and 3 acceleration channels
  • 16-bit data output
  • SPI and/or I2C serial interfaces
  • Analog supply voltage 2.16V to 3.6V
  • Power-down mode / low-power mode
  • Programmable interrupt generators for freefall, motion detection and magnetic field detection
  • Embedded temperature sensor

Here is a picture of the module I bought

lsm303-module

This is a schematic of a typical module such as the one above

lsm303-module-schematic

 

Now lets look at a layout showing how to connect the module to our Arduino

 

Schematic and layout

Quite a straightforward connection being an I2C device, as this module has a 3v3 voltage regulator you can connect this to your Arduino’s 5v.

arduino-and-lsm303d_bb

Code

 

#include <Wire.h>
#include <LSM303.h>
 
LSM303 compass;
 
char report[80];
 
void setup()
{
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();
}
 
void loop()
{
  compass.read();
 
  snprintf(report, sizeof(report), "A: %6d %6d %6d    M: %6d %6d %6d",
    compass.a.x, compass.a.y, compass.a.z,
    compass.m.x, compass.m.y, compass.m.z);
  Serial.println(report);
 
  delay(500);
}

 

Testing

Open the Serial Monitor window and you should see something like this

A: 1408 -10144 13072 M: -54 149 -458
A: 2944 -8896 13152 M: -56 121 -469
A: -2704 -10432 -1216 M: 346 431 200
A: 896 -8992 20512 M: 172 456 -259
A: 21296 -14512 25712 M: -171 481 275
A: -14000 16512 -12064 M: 242 141 475
A: 7296 -10800 -7216 M: -409 362 220
A: 31648 1840 -5344 M: -551 205 52
A: -272 30544 -6688 M: 248 -440 335
A: -6992 -7504 -3472 M: -13 566 -91
A: -1632 -16992 20464 M: -53 584 49

 

Links
You can pick up one of these modules for about $5

AliExpress.com Product – Accelerometer + 3 Axis Magnetometer Module Sensor

FacebookTwitterGoogle+TumblrStumbleUponRedditLinkedInWhatsAppPinterestBaiduBufferDeliciousDiigoDiggOdnoklassnikiSina WeiboWordPressBlogger PostEmailShare

Arduino PCA9685 example

The PCA9685 is an I²C-bus controlled 16-channel LED controller optimized for Red/Green/Blue/Amber (RGBA) color backlighting applications. Each LED output has its own 12-bit resolution (4096 steps) fixed frequency individual PWM controller that operates at a programmable frequency from a typical of 24 Hz to 1526 Hz with a duty cycle that is adjustable from 0 % to 100 % to allow the LED to be set to a specific brightness value. All outputs are set to the same PWM frequency.

Each LED output can be off or on (no PWM control), or set at its individual PWM controller value. The LED output driver is programmed to be either open-drain with a 25 mA current sink capability at 5 V or totem pole with a 25 mA sink, 10 mA source capability at 5 V. The PCA9685 operates with a supply voltage range of 2.3 V to 5.5 V and the inputs and outputs are 5.5 V tolerant. LEDs can be directly connected to the LED output (up to 25 mA, 5.5 V) or controlled with external drivers and a minimum amount of discrete components for larger current or higher voltage LEDs.

Here is the module I purchased

pca9685module

Layout

This example only shows one led connected, my test board had all 16 connected

arduino-pca9685_bb

 

Code

You will need to add the Adafruit PWM Servo driver library – https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library/archive/master.zip

This is the default code

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
 
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
 
void setup() {
  Serial.begin(9600);
  Serial.println("16 channel PWM test!");
  pwm.begin();
  pwm.setPWMFreq(1600);  // This is the maximum PWM frequency
 
  // save I2C bitrate
  uint8_t twbrbackup = TWBR;
  // must be changed after calling Wire.begin() (inside pwm.begin())
  TWBR = 12; // upgrade to 400KHz!
 
}
 
void loop() {
  // Drive each PWM in a 'wave'
  for (uint16_t i=0; i<4096; i += 8) 
  {
    for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) 
    {
      pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 );
    }
  }
}

 

Link

 
16 Channel 12-bit PWM/Servo Driver-I2C interface-PCA9685 for arduino or Raspberry pi shield module servo shield

FacebookTwitterGoogle+TumblrStumbleUponRedditLinkedInWhatsAppPinterestBaiduBufferDeliciousDiigoDiggOdnoklassnikiSina WeiboWordPressBlogger PostEmailShare