Friday 11 November 2016

Android App controlled 2WD RC Robot Platform Car Kit with BT hc-06 +Arduino UNO + L293D motor shield






1. The Kit
This kit is available from our eBay store.
It comes with the following  parts:

2 x Geared motors + 2 x Tyres/wheels + 2 x Motor fixings
4 x motor cables.
1 x  transparent acrylic glass plate 
1 x L293D motor shield
1 x  Arduino UNO328 controller board (CH340 usb driver)
1 x HC-06 Bluetooth module
1 x Battery holder (12V , 8 x AA / batteries not included)
2 x motor speed encoding disks (Use with IR optocoupler sensors which are not included)
1 x USB cable for arduino 
1x Castor wheel + 4 x Copper pillar + Screws kit 
1x on/off toggle mini switch, extra screws and nuts, tie cables etc


2. Connect the motors


Connect the motors and wheels as shown in the  figure 1.  Solder the red and black wires as shown. These correspond to the positive and negative of the motors/battery terminals. If you connect the red and black to the +ve and -ve of the battery , all the motors/ wheels should spin in the same direction. If any wheel spins in a different direction swap the wires on the motor terminals to correct the spin.

Figure 1: Connecting wheels and motors




2. Connect Bluetooth Hc-06 to arduino
Solder wires to arduino uno according to the following connection table.


HC-06
Arduino
VCC
3.3v
GND
GND
TXD
RXD
RXD
TXD
Figure 2



Figure 3:

3. Connect the motor shield

and tie to chassis as shown below



Figure 4



4. Connect motor cables and power to Arduino shield
connect both motors to the shied as shown in figure below. The terminal are marked as M3 and M4 on the shield. Also connect the battery terminals to power the board.


Figure 5



5. Arduino code:

Before uploading the code to arduino uno, always disconnect the power to HC-06.

To control the motors, i used the library <AFMotor.h>.

#include <AFMotor.h> //creates two objects to control the terminal 3 and 4 of motor shield AF_DCMotor motor1(3); AF_DCMotor motor2(4); char command; void setup() { Serial.begin(9600); //Set the baud rate to your Bluetooth module. } void loop(){ if(Serial.available() > 0){ command = Serial.read(); Stop(); //initialize with motors stoped //Change pin mode only if new command is different from previous. Serial.println(command); switch(command){ case 'F': forward(); break; case 'B': back(); break; case 'L': left(); break; case 'R': right(); break; } } } void forward() { motor1.setSpeed(255); motor1.run(BACKWARD); motor2.setSpeed(255); motor2.run(BACKWARD); } void back() { motor1.setSpeed(255); motor1.run(FORWARD); motor2.setSpeed(255); motor2.run(FORWARD); } void left() { motor1.setSpeed(255); motor1.run(BACKWARD); motor2.setSpeed(0); motor2.run(RELEASE); } void right() { motor1.setSpeed(0); motor1.run(RELEASE); motor2.setSpeed(255); motor2.run(BACKWARD); } void Stop() { motor1.setSpeed(0); motor2.run(RELEASE); motor2.setSpeed(0); motor2.run(RELEASE); }

6. Android App


The link to Download the app from google play store is:
A screen shot of the app is shown in Fig 6. The app has both accelerometer and button control functionality.


Figure 6: Bluetooth RC Controller









7. Results: 





Thursday 28 April 2016

Blink LED on Arm Cortex M3 STM32F103c8t6 Dev board + ST-LINK V2



SOFTWARE SETUP

ARDUINO

1. Download and install the Arduino  from the Arduino website 
2. Download the zip of the additional files  from Roger Clark's GitHub repository    https://github.com/rogerclarkmelbourne/Arduino_STM32
3. Assuming you are using Windows .. Copy the files from the zip to My Documents\Arduino\hardware so     that inside the hardware folder there is the Arduino_STM32 folder.
4. Go Arduino Menu then Boards Manager and install Arduino SAM Boards



5. Restart the Arduino IDE.
6. Select the board settings from the Arduino IDE Menu as follows:



























ST-LINK V2

1. Download and install the st-link utility v 3.8.0 and driver from ST.com website.
2. Update the firmware to the latest from the utility menu.




HARDWARE SETUP




hook it up to the STM32 board using jumper wires connected from the ST-Link to the JTAG socket using the following pinout.

ST-Link      <>     STM32

 GND           -> GND (4) [JTAG]
 3V3/VDD  ->  3V3  [BOARD]
 CLK           -> SWCLK (9) [JTAG]
 IO/SWD     -> SWDIO (7) [JTAG]


LED is connected between Board Pin PC13 and GND  in series with 330 Î© resistor.



ARDUINO CODE


#define LED PC13

void setup() {
  pinMode(LED, OUTPUT);
}

void loop() {
  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

Wednesday 27 April 2016

NodeMCU + PIR sensor HC-SR501 + ThingSpeak = Motion Detection alert Via Twitter





To get API keys register at https://thingspeak.com/  and then on its twitter app on https://thingspeak.com/apps/thingtweet

Code

//nodeMCU v1.0 (black) with Arduino IDE
//nodemcu pinout https://github.com/esp8266/Arduino/issues/584

#include <ESP8266WiFi.h>
#include <pins_arduino.h>
#define myPeriodic 15 //in sec | Thingspeak pub is 15sec

long min=0;
int PIRpin = 14;
int PIRvalue=0;
const char* server = "api.thingspeak.com";
String apiKey ="Your-api-key";
String api_key_ts="your-api-key-ts";
const char* MY_SSID = "wifi=ssid"; 
const char* MY_PWD = "password";

int failedCounter = 0;
long lastConnectionTime = 0; 
boolean lastConnected = false;
int sent = 0;

void setup() {
  pinMode(PIRpin, INPUT);
  Serial.begin(115200);
  connectWifi();
}

void loop() {
  PIRvalue=digitalRead(PIRpin);
if (PIRvalue==HIGH){
  Serial.println(String(sent)+"Motion detected ");
  sendMotion(PIRvalue);
  updateTwitterStatus("My thing is social @thingspeak, Motion detected, possible intruder!");
  int count = myPeriodic;
  while(count--)
  delay(1000);}
  else{
    Serial.println(String(sent)+"Motion NOT detected ");
  sendMotion(PIRvalue);
  int count = myPeriodic;
  while(count--)
  delay(1000);}
    
}

void connectWifi()
{
  Serial.print("Connecting to "+*MY_SSID);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("Connected");
  Serial.println("");  
}//end connect

void sendMotion(int PIRv)
{  
   WiFiClient client;
  
   if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
   Serial.println("WiFi Client connected ");
   String postStr = apiKey;
   postStr += "&field1=";
   postStr += String(PIRv);
   postStr += "\r\n\r\n";
   
   client.print("POST /update HTTP/1.1\n");
   client.print("Host: api.thingspeak.com\n");
   client.print("Connection: close\n");
   client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(postStr.length());
   client.print("\n\n");
   client.print(postStr);
   delay(1000);
   
   }//end if
   sent++;
 client.stop();
}//end send
void updateTwitterStatus(String tsData)
{
  
  WiFiClient client;
  if (client.connect(server, 80))
  { Serial.println("WiFi Client connected to thingSpeak ");
    // Create HTTP POST Data
    
    min =millis()/(1000);
    tsData = min+tsData;
    tsData = "api_key="+api_key_ts+"&status="+tsData;
            
    client.print("POST /apps/thingtweet/1/statuses/update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");

    client.print(tsData);
    
    if (client.connected())
    {
      Serial.println("Connecting to ThingSpeak/thingtweet...");
      Serial.println();
      
    }
}
}

Saturday 20 February 2016

1.8" Serial SPI 128x160 Color TFT LCD Module Display

TFT LCD Screens (Thin-film-transistor liquid crystal display) are great graphical displays to display information.  They are a variant of a liquid crystal display (LCD) which uses TFT technology to improve image qualities such as addressability and contrast.  They are used often in video games, smart phones, cell phones, and sometimes even TV's.  Now, with the technology and accessibility today, you can use one with your Arduino!

Features



  • Size: 1.8 inch
  • Dot Matrix: 128*160
  • Size: 54mm(length)*34mm(width)
  • Input Voltage: 5V/3.3V
  • Driver IC: S6D02A1 / ST7735
  • Pin Definition: 1-RST 2-CE 3-D/C 4-DIN 5-CLK 6-UCC 7-BL 8-GND
  • It has PCB backplane with power IC, SD card socket
  • It need 4 IO port at least to drive.


Hardware Setup


Pinouts of the TFT are shown in the picture above. Connect the TFT pin to Arduino as shown in the table below. also connect 1KΩ resistors to all the data lines of TFT pins 1 , 2, 3, 4, 5. I have also connected  a 100 Ω resistor between pin 7. BL and +5V.


TFT                                    UNO
5. Clk        >1KΩ>               13
4. DIN       >1KΩ>               11
3. D/C        >1KΩ>              9
2. CE         >1KΩ>               10
1. RST       >1KΩ>              8
6. VCC                                 +5V
7. BL         >100Ω>             +5V
8. GND                                GND

The full setup is shown in picture below.






Software Setup:

Open the Arduino IDE and from Menu "Manage libraries " Install the "Ucglib by oliver"  library.



Now upload the following code to Arduino.

Arduino Code:


#include <SPI.h>
#include "Ucglib.h"

Ucglib_ST7735_18x128x160_HWSPI ucg(/*cd=*/ 9 , /*cs=*/ 10, /*reset=*/ 8);

void setup(void)
{  
  delay(1000);
  ucg.begin(UCG_FONT_MODE_TRANSPARENT);
  ucg.clearScreen();
}

void loop(void)
  ucg.setFont(ucg_font_ncenR12_tr);
  ucg.setColor(255, 0, 0);
  ucg.setPrintPos(10,25);
  ucg.print("Hello World!");

  ucg.setColor(0, 0, 255);
  ucg.setPrintPos(50,60);
  ucg.print("By");

  ucg.setColor(20, 255, 20);
  ucg.setPrintPos(10,100);
  ucg.print("ALICTRONIX");
  delay(500); 
}

Results:









Sunday 17 January 2016

Blink LED on NodeMcu DevKit ver1.0 / ESP8266 12E, Lua, WIFI, IOT,

Introduction:

Wi-Fi is an essential bit of kit for any Internet of Things (IoT) DIY projects, but our favorite Arduino doesn’t come with Wi-Fi, and adding in a Wi-Fi shield can increase the costs substantially.
Meet the Arduino Killer: ESP8266 (also known as NodeMCU) was originally marketed as a low cost Wi-Fi add-on for Arduino boards, until the hacker community realized you could cut the Arduino out of the equation entirely.



In less than a year, the ESP8266 has rocketed in popularity, and is now so well supported and developed that if you’re currently using Arduino, you need to stand up and take note.
There’s quite a few models of ESP8266 around now, but we recommend this one: ESP-12E (also known as NodeMCU 2.0). This board includes the serial driver needed to program the chip, and has a built-in power regulator, as well as lots of IO pins.This NodeMCU Devkit is available from our eBay Store.

Getting Started with ESP8266-12E:

Using Micro usb to standard usb cable Connect  ESP8266-12E  to your PC. we are using windows 7.

Please wait and allow the windows to install the USB driver as shown below.


NodeMCU is connected to COM5 . This can also be verified from Device Manager.



Method 1: Arduino IDE

This is the easier of the two methods requiring only Arduino IDE

  • Install the latest Arduino from the Arduino website.
  • Start Arduino and open Preferences window.
  • Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
  • Open Boards Manager from Tools > Board menu and install esp8266 platform 

Selecting the NodeMCU baord from Tools Menu





Restart Arduino IDE and select blink Example for ESP8266 and upload.



Results:




Method 2: Flashing the Firmware:

This Method Involves flashing the firmware and then uploading the lua code via ESPlorer.

download the latest firmware from the following link

or the direct link

we are using the firmware: nodemcu_float_0.9.6-dev_20150704.bin

Download and run the flasher software from github

we are using the 64 bit version of the flasher.

Select the firmware file by clicking on the gear icon.



Then press the Flash(F) button to start the firmware flash process.




Once finished  press the reset button on the NodeMCU.

Running Blink led program:

Now download and run the ESPlorer IDE from the following link
connect to NodeMCU by pressing the Open button on the top of right panel.


After successful connection  some message and a prompt is displayed.


Now we are ready to upload our first program "Blink.lua" to NodeMCU. Press [Save to ESP] button to upload, the red led on ESP will start flashing with 1 sec interval. Please note 1,000,000 us = 1 sec.

"Blink.lua" code:

              while 1 do
              gpio.write(0,gpio.HIGH)
              tmr.delay(1000000)
              gpio.write(0,gpio.LOW)
              tmr.delay(1000000)

              end



Results:





WIFI Scanner:


Setup:


OLED -> NodeMcu

-SDA     ->   D5
-SCL      ->   D6
-VCC      ->  3.3V
-GND     ->   GND

Code:


wifi.setmode(wifi.STATION) --Set mode to STATION so he chip can receive the SSID broadcast
function init_OLED(sda,scl) --Set up the u8glib lib
     sla = 0x3c
     i2c.setup(0, sda, scl, i2c.SLOW)
     disp = u8g.ssd1306_128x64_i2c(sla)
     disp:setFont(u8g.font_6x10)
     disp:setFontRefHeightExtendedText()
     disp:setDefaultForegroundColor()
     disp:setFontPosTop()
end
init_OLED(5,6) --Run setting up
tmr.alarm(0,3000,1,function() --A timer, which used to run the following program 
    wifi.sta.getap(function(t) 
         disp:firstPage()
         repeat
            lines = 0
            for k,v in pairs(t) do
                disp:drawStr(0,lines * 11,k.." "..v:sub(3,5).."dbi") --Print the data out
                lines = lines + 1
            end
        until disp:nextPage() == false
    end)
end)

Results:





Saturday 16 January 2016

Hello World 0.96 inch 128X64 I2C OLED, on Arduino Uno, using u8glib library

Introduction:

 OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.
Blue and White Character OLEDs are available from our eBay Store.

Features:

It's a 0.96" 128X64 OLED, I2C (or IIC) interface, with SSD1306 driver, 3.3/5V compatible.

1. A simplified manufacturing process compared to TFT-LCD
2. Self-emitting light, in contrast to the required backlight for TFT-LCD
3. High luminosity 
4. Lightweight and thin (less than 2 mm)
5. Capable of wide viewing angles>160
6. Low operating voltage and power consumption
7. Quick response (< second level)
8. Wide range of operating temperatures (-30c to 70c)

Specifications:


  •          High resolution: 128 * 64
  •       Viewing angle:> 160 degree
  •       Supports many control chip: Fully compatible with Arduino, 51 Series, MSP430 Series, STM32 / 2, CSR IC, etc.
  •       Ultra-low power consumption: full screen lit 0.08W
  •       Voltage: 3V ~ 5V DC
  •       Working Temperature: -30 c ~ 70 c
  •       Module Size: 27.0MM * 27.0MM * 4.1MM
  •       I2C/IIC Interface, need 2 IO only.
  •       Driver IC: SSD1306
  •       Character Colour: White



Hardware Setup:

There are 4 pin on the OLED module, GND, VCC, SCL and SDA. Connect the oled module to your Breadboard. Get four male to male dupont jumper wires and Connect to Arduino as shown in the following image and table:


OLED -> Arduino

-SDA     ->   A4
-SCL      ->   A5
-VCC      ->  3.3V

-GND     ->   GND



Software Setup:

u8glib (Universal Graphics Library for 8 Bit Embedded Systems) is a  graphics library with support for many different displays.
To install u8glib go to manage libraries in Arduino IDE menu:

and from the list of available libraries install u8glib by oliver library.


find and load the HelloWorld example in the library.


In the HelloWorld, only un-comment the following constructor to make it work:
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);

or use the following code:

Arduino Code:

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);  // I2C / TWI

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here 
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 10, "Hello World!");
  u8g.drawStr( 50, 35, "By");
  u8g.drawStr( 10, 56, "Alictronix!");
}

void setup(void) {
  // flip screen, if required
  // u8g.setRot180();
 
  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
}

void loop(void) {
  // picture loop
  u8g.firstPage(); 
  do {
    draw();
  } while( u8g.nextPage() );
 
  // rebuild the picture after some delay
  delay(50);
}

Results:



White Character Display:





Blue Character Display: