Monday, June 11, 2018
Configuring the Raspberry Pi as an alternative to Chromecast.
This blog is about how to configure the Raspberry Pi as an alternative to Chromecast and I can stream any video from the internet using my Smartphone and play it on my large screen TV.
There are lots of places where the configuration is described in detail.
But I used this link and it is straight forward.
https://www.instructables.com/id/Raspberry-Pi-As-Chromecast-Alternative-Raspicast/
I used Raspicast as an app on my SmartPhone to stream the data.
There are lots of places where the configuration is described in detail.
But I used this link and it is straight forward.
https://www.instructables.com/id/Raspberry-Pi-As-Chromecast-Alternative-Raspicast/
I used Raspicast as an app on my SmartPhone to stream the data.
Tuesday, May 29, 2018
Programming the 5V DC Motor and controlling speed using the L293D motor
This blog is about using the PWM signals available on the Arduino Nano to control the speed of the Hobby DC Motor 5V.
Parts required :
Hobby DC Motor
L293D Motor Driver.
Arduino Nano and pair of wires.
Code is fairly simple :
int enable2 = 9;
int in3 = 10;
int in4 = 11;
void setup()
{
pinMode(enable2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop()
{
analogWrite(enable2, 138); // Any value between 0 and 255
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
/*delay(10000);
analogWrite(enable2, 200); // Any value between 0 and 255
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(10000);
*/
}
Connections :
Nano :
Pin 10 and 11 to Inputs of the L293D.
Pin 9 of Arduino to Enable Pin of the L293D.
5V power to supply both the Vss and the Power to the Motor.
Wednesday, May 23, 2018
Facial Recognition using Python and Open CV APIs ( Computer Vision )
This is my Facial Recognition blog. Here I have trained the Python backend to recognise faces and identify when the new image is provided.
The code can be modified to handle Video later.
https://github.com/kiranshashiny/Facial-Recognition-using-OpenCV-APIs
Saturday, September 23, 2017
Programming the ATtiny 85 chip using Arduino as a Programmer
The ATtiny 85 is a 8 pin chip, and can be programmed with an Arduino.
In this blog - I will attempt to turn LEDs on and off using the Arduino as a Programmer and configuring the ATtiny to read from the Arduino.
This is the flow diagram
Computer -> Arduino -> ATtiny85 -> LEDs.
i.e ( Mac OS -> Arduino IDE -> USB cable to Arduino -> ATtiny85 -> LEDs to Pin PB3 and PB4 )
Prerequisites :
Arduino Uno -1
Arduino IDE v1.6.12 and above installed on your laptop.
ATtiny 85 - 1 ( 8 pin )
2 LEDs
270 ohm resistors -connected to the LEDs Anode - 2
and access to this package.
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
Pin Diagram of ATTiny 85 Pin diagram.

Connections :
Pin 13 SCL (7)
Pin 12 MISO ( 6)
Pin 11 MOSI ( 5)
Pin 10 Reset (1)
GND GND (4)
Vcc +5V Vcc (8)
PB3-> 270 ohm resistor -> Anode of LED
Common GND Cathode of LED
==
Setup Programmer on the Arduino IDE as follows:
Include this line into the Arduino -> Preferences -> "Additional Boards Manager URL" pane in the Arduino Boards Manager:https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

Bring up the "Tools" -> "Boards Manager" and install the "attiny" package by David A. Mellis.
Click on Install.

Check that the install did work, by Tools -> Board, and you see the ATtiny85.

Now, you will see the ATtiny 25/45/85 in the "Tools -> Boards" panel - Select the ATtiny.
This indicates successful installation of the package in the IDE.
=========================================
Next, Reset the "Boards" back to Arduino Uno.

Select File-> Examples -> ArduinoISP -> ArduinoISP and upload it. This will prepare the Arduino Uno to pretend to be an ISP for the ATTiny.
Programmer -> AVRISP mkrll (setting is default as in Arduino)
( at this time the ATTiny may be connected , but will have no effect on this )
Possible errors and how to resolve it:
If you get a "Serial undefined" error, check if the Board -> Arduino Uno, ( it may have been set to ATTiny 85 ). Reset to Arduino Uno.
If you get a "avrdude: ser_open(): can't open device "/dev/cu.wchusbserial1420": No such file or directory
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troub "
Check if the Tools->Port is set to the Arduino's COM port .

When successful.
File -> Examples -> Basics -> Blink
Change the "LED_BUILTIN" to 3 ("PB3" also works), indicating PB4 of the ATTiny85.
Add a new line ( copy and paste ) and set physical pin 2 , indicating PB3 of the ATTiny85
[ PB3 is physical pin 2 of ATTiny85 ]
[ PB4 is physical pin 3 of the ATTiny85 ]

Same in text format.
Blink Code is modified to turn LEDs on and off at Pins PB3 and PB4.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite (4, HIGH);
delay(1000); // wait for a second
digitalWrite(3, LOW); // turn the LED off by making the voltage LOW
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Change the Board to ATtiny85

Notice the setting " Processor -> Attiny85"

Set the Clock Internal 8Mhz

Burn Bootloader ( not required - during 2nd trial )

If successful, the status should say success.
If not, then check if the Programmer is set to -> "Arduino as ISP". It could be that you have set it to "ArduinoISP". This is confusing ! There are two entries and the correct one should be as shown above.
Or else you will get a "Could not upload" error.

Now Upload the code for the LED, Click on the right arrow button in the top panel.
At this time if you get the error message "not responding", go back and check the Tools-> Programmer -> Arduino as ISP.
( it is set to Programmer -> AVRISP -> mkll as default for the Arduino Uno)

Assuming that the LEDs are connected - they should start blinking.
Troubleshooting :The Arduino ISP has to be uploaded to the Arduino first , File -> Examples -> ArduinoISP -> Arduino ISP
Next, the correct package has to be installed - from
Include this line into the Arduino -> Preferences -> "Additional Boards Manager URL" pane in the Arduino Boards Manager:
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
If you are getting a "Not responding to programmer" - that means - the Arduino was not File-> Examples -> ArduinoISP was not installed first ! to the Arduino.
So go back and install this first.

Monday, September 19, 2016
Detecting Colors thru a sensor using Arduino and Publishing to IBM Bluemix IoT Watson Platform.
This blog is about Publishing Color sensor data to the IBM Bluemix IoT Watson platform using the MQTT ( Message Queue Transport Telemetry Protocol)
The microcontroller is the Arduino Uno with the Ethernet shield connected to the Color Sensor.
Data being Published is the frequency of the color and is visualized on the local laptop and on the Bluemix by installing the Node.js visualization platform.
At this point : I'd assume that the user has created the device, credentials, Authentication tokens etc on the IoT platform in Bluemix.
To get started on IoT Platform on the IBM BLuemix and get a starter trial go to - http://console.ng.bluemix.net
The color sensor used is the TCS3200 and has 8 pins.
S0..S3 goes to Pin 4,5, 6 and 7
OUT goes to Pin 8 on the Arduino
LED and Vcc goes to 5 V on the Arduino.
In this snap below I have a tomato placed under the sensor which detects the color.

The theory behind this is the photo diode in the middle of the sensor detects the color of the object and can transmit different frequencies.
The frequency is then mapped to a value between 0 and 256. Lower the mapping means the color is either Red , Green or Yellow depending on what is the settings for the sensor.
Each sensor sensitivity can be different and that's why this is called as the programmable sensors wherein we can program the value of the material being programmed.
The code is in https://github.com/kiranshashiny/mqtt_arduino_color_sensor_registered_to_IBMBluemix
The microcontroller is the Arduino Uno with the Ethernet shield connected to the Color Sensor.
Data being Published is the frequency of the color and is visualized on the local laptop and on the Bluemix by installing the Node.js visualization platform.
At this point : I'd assume that the user has created the device, credentials, Authentication tokens etc on the IoT platform in Bluemix.
To get started on IoT Platform on the IBM BLuemix and get a starter trial go to - http://console.ng.bluemix.net
The color sensor used is the TCS3200 and has 8 pins.
S0..S3 goes to Pin 4,5, 6 and 7
OUT goes to Pin 8 on the Arduino
LED and Vcc goes to 5 V on the Arduino.
In this snap below I have a tomato placed under the sensor which detects the color.

The theory behind this is the photo diode in the middle of the sensor detects the color of the object and can transmit different frequencies.
The frequency is then mapped to a value between 0 and 256. Lower the mapping means the color is either Red , Green or Yellow depending on what is the settings for the sensor.
Each sensor sensitivity can be different and that's why this is called as the programmable sensors wherein we can program the value of the material being programmed.
The code is in https://github.com/kiranshashiny/mqtt_arduino_color_sensor_registered_to_IBMBluemix
Saturday, May 07, 2016
How to turn LED dim and bright back again, using PWM On Raspberry Pi.
Code in Python:
Here I am using the Raspberry Pi Model B, connected to my Mac Laptop.
This was an experiment to try out using the PWM option available on the Raspberry.
The LEDs are connected to physical Pins 11
The white LED at one end is connected to Pin 11, ( i.e the GPIO17 ) , hence I'm using GPIO.BOARD in the python definition.
pi@raspberrypi~ $cat servo.py
import RPi.GPIO as GPIO # always needed with RPi.GPIO
from time import sleep # pull in the sleep function from time module
GPIO.setmode(GPIO.BOARD) # choose BCM or BOARD numbering schemes. I use BCM
GPIO.setup(11, GPIO.OUT)# set GPIO 11 as output for white led
white = GPIO.PWM(11, 100) # create object white for PWM on port 11 at 100 Hertz
white.start(0) # start white led on 0 percent duty cycle (off)
# now the fun starts, we'll vary the duty cycle to
# dim/brighten the leds, so one is bright while the other is dim
pause_time = 0.02 # you can change this to slow down/speed up
try:
while True:
for i in range(0,101): # 101 because it stops when it finishes 100
white.ChangeDutyCycle(i)
sleep(pause_time)
for i in range(100,-1,-1): # from 100 to zero in steps of -1
white.ChangeDutyCycle(i)
sleep(pause_time)
except KeyboardInterrupt:
white.stop() # stop the white PWM output
GPIO.cleanup() # clean up GPIO on CTRL+C exit
Here I am using the Raspberry Pi Model B, connected to my Mac Laptop.
This was an experiment to try out using the PWM option available on the Raspberry.
The LEDs are connected to physical Pins 11
The white LED at one end is connected to Pin 11, ( i.e the GPIO17 ) , hence I'm using GPIO.BOARD in the python definition.
pi@raspberrypi~ $cat servo.py
import RPi.GPIO as GPIO # always needed with RPi.GPIO
from time import sleep # pull in the sleep function from time module
GPIO.setmode(GPIO.BOARD) # choose BCM or BOARD numbering schemes. I use BCM
GPIO.setup(11, GPIO.OUT)# set GPIO 11 as output for white led
white = GPIO.PWM(11, 100) # create object white for PWM on port 11 at 100 Hertz
white.start(0) # start white led on 0 percent duty cycle (off)
# now the fun starts, we'll vary the duty cycle to
# dim/brighten the leds, so one is bright while the other is dim
pause_time = 0.02 # you can change this to slow down/speed up
try:
while True:
for i in range(0,101): # 101 because it stops when it finishes 100
white.ChangeDutyCycle(i)
sleep(pause_time)
for i in range(100,-1,-1): # from 100 to zero in steps of -1
white.ChangeDutyCycle(i)
sleep(pause_time)
except KeyboardInterrupt:
white.stop() # stop the white PWM output
GPIO.cleanup() # clean up GPIO on CTRL+C exit
Thursday, March 17, 2016
Turning on LEDs on/off using NodeMCU
Code for turning LEDs ON/OFF using Node MCU.
I followed instructions found in this blog:
http://www.cnx-software.com/2015/10/29/getting-started-with-nodemcu-board-powered-by-esp8266-wisoc/

Troubleshooting Upload using luatool when you hit an TransportError
This blog is to show how to resolve an error during uploading code you have written for the NodeMCU device from the Mac and in my case Mac OS Yosemite 10.10.5
The error that showed up when I tried to upload from my laptop:

( Just so that you know : this is where I downloaded the luatool ).
http://www.cnx-software.com/2015/10/29/getting-started-with-nodemcu-board-powered-by-esp8266-wisoc/

The error shown in blog means there is another communication program (in my case it is Cool Term ) running on my laptop, which was used to send commands to the NodeMCU firmware.
So I did "disconnect" this to device on the CoolTerm, and was able to run the upload the lua script from my Mac to device successfully.

Getting IP address of NodeMCU with a simple script, and some validation tips.
First.
go to the Wifi Connections, - Uncheck the "Internet Sharing",
and click on Wifi Options.



Now, reset the device by clicking the 'RST" button.
http://www.cnx-software.com/2015/10/29/getting-started-with-nodemcu-board-powered-by-esp8266-wisoc/

The Router _ESSID is "Network Name" as found in the Configuration panel of the Mac Connections window.

The password would be set in this field.

End Result : 192.168.2.3 is the IP address.

Troubleshooting tips:
is the Network name and the Password set correctly in the code.
wifi.setmode(wifi.STATION)
wifi.sta.config("networkname","password")
print(wifi.sta.getip())
Next.. check that the Internet sharing is set ON.

Validation:
ping 192.168.2.3

I found that if the Ping to this device does NOT work- then just click on the RST button on the device and it should get started.
Getting the IP address of nodeMCU - using CoolTerm and a simple script.
Here I am trying to view the access points and also get the IP address assigned to the device using some basic Lua scripts.

https://smartarduino.gitbooks.io/development-of-nodemcu/content/subsection_42_wifi_mode.html

https://smartarduino.gitbooks.io/development-of-nodemcu/content/subsection_42_wifi_mode.html
Viewing the Wifi Access Points around my NodeMCU.
The Node MCU has a wifi built into - so that it can connect to the Internet, and also communicate to other devices like a Laptop, Smartphone etc.
This below is my first attempt to connect the wifi module (Node MCU ) to the view the Access Points around it
Following is from this blog
https://smartarduino.gitbooks.io/development-of-nodemcu/content/subsection_34_wifi_test.html


This below is my first attempt to connect the wifi module (Node MCU ) to the view the Access Points around it
Following is from this blog
https://smartarduino.gitbooks.io/development-of-nodemcu/content/subsection_34_wifi_test.html


Flashing the NodeMCU - first time. - Simple steps and challenges I faced.
Flashing the NodeMCU development kit.

Since I was not getting a good response after I connected the NodeMCU to my Mac ( 10.10.5 ) Yosemite using CoolTerm. http://freeware.the-meiers.org/
https://github.com/nodemcu/nodemcu-devkit/wiki/Getting-Started-on-OSX

I decided to try flashing the NodeMCU to get it back to life.
Note : when using the CoolTerm -I am assuming that the right driver is installed SL USB to UART. ( follow link below)
Important : You cannot change the Port to USB to UART from any other if the CoolTerm is connected.
You have to first disconnect it and then go to Options and then select the right driver.

Flashing the NodeMCU : Command.

After flashing which took a minute( I could see a blue light blinking on the device )
I started CoolTerm and when I connected I saw the message that Cannot Open init.lua with some garbage characters as shown above.
So, I disconnected again ( by clicking on Disconnect ) button on CoolTerm, and hit the RST.
Connected back and I got some valid characters.

The parameters were

At this point - it is a blank firmware.
So - I had to read the init.lua by following instructions as listed here.
http://www.electrodragon.com/w/ESP8266_NodeMCU_Dev_Board


Since I was not getting a good response after I connected the NodeMCU to my Mac ( 10.10.5 ) Yosemite using CoolTerm. http://freeware.the-meiers.org/
https://github.com/nodemcu/nodemcu-devkit/wiki/Getting-Started-on-OSX

I decided to try flashing the NodeMCU to get it back to life.
Note : when using the CoolTerm -I am assuming that the right driver is installed SL USB to UART. ( follow link below)
Important : You cannot change the Port to USB to UART from any other if the CoolTerm is connected.
You have to first disconnect it and then go to Options and then select the right driver.

Flashing the NodeMCU : Command.

After flashing which took a minute( I could see a blue light blinking on the device )
I started CoolTerm and when I connected I saw the message that Cannot Open init.lua with some garbage characters as shown above.
So, I disconnected again ( by clicking on Disconnect ) button on CoolTerm, and hit the RST.
Connected back and I got some valid characters.

The parameters were

At this point - it is a blank firmware.
So - I had to read the init.lua by following instructions as listed here.
http://www.electrodragon.com/w/ESP8266_NodeMCU_Dev_Board




