Believe me guys i struggled a lot to Interface DHT11 sensor with the Raspberry Pi for my smart home. As i have already opted Pi4J for JAVA programming it was hard to interface with Pi as Pi4J doesn't support one wire protocol. I did lot of research but nothing worked out. Finally i gave a try to python and it worked perfectly. But as my complete firmware is using JAVA. I opted a way that i will interface it using python but will be executed from JAVA.
Thursday, February 26, 2015
DHT11 Sensor Interfacing with Raspberry Pi
Believe me guys i struggled a lot to Interface DHT11 sensor with the Raspberry Pi for my smart home. As i have already opted Pi4J for JAVA programming it was hard to interface with Pi as Pi4J doesn't support one wire protocol. I did lot of research but nothing worked out. Finally i gave a try to python and it worked perfectly. But as my complete firmware is using JAVA. I opted a way that i will interface it using python but will be executed from JAVA.
Monday, November 24, 2014
External ADC with Raspberry Pi.
Really I tried a lot with MCP3208 external ADC to interface with the Raspberry pi. Searched for various codes but nothing was available in JAVA. So after some research i got some python code and modified that to JAVA. in this i have used the Pi4J library.
/**** *Author : Bikash Narayan Panda *Use : This is used to read ADC data foem the MCP3208 SPI based ADC. *Date :19/Nov/2014 *Tags: Please Include the Pi4J Library. * * **/ import java.io.IOException; import com.pi4j.io.gpio.GpioController; import com.pi4j.io.gpio.GpioFactory; import com.pi4j.io.gpio.GpioPinDigitalInput; import com.pi4j.io.gpio.GpioPinDigitalOutput; import com.pi4j.io.gpio.PinPullResistance; import com.pi4j.io.gpio.PinState; import com.pi4j.io.gpio.RaspiPin; public class SensorTest { public static int readadc(int adcnum, GpioPinDigitalOutput clockpin, GpioPinDigitalOutput mosi
Thursday, October 30, 2014
Modify your old PC SMPS to BenchTop Power Supply Unit
Many time we do have old SMPS of no use to the computers. Those SMPS can be modified as bench-top power supply system providing -12,+12,+5,+3.3 volts. I have used one to power my all arduino based home automation modules and the Raspberry Pi. Here i am going to post how to mod an old SMPS .
You just need following components along with some basic tools
1.Screw Terminals.
2.Switch (On/Off).
3.10Watt Resistive load (May be 5K or 10K i have used 4.7K working fine)
Friday, September 12, 2014
Using Raspberry Pi Serial Port
By default the Raspberry Pi’s serial port is configured to be used for
console input/output, it means you can't use the Serial Port in your
programs and needs to be
disabled.To enable the serial port for your own use you need to disable login on the port. There are two files that need to be edited
The first and main one is
The first and main one is
/etc/inittab
This file has the command to enable the login prompt and this needs to be disabled. Edit the file and move to the end of the file. You will see a line similar to
Wednesday, September 10, 2014
Algotithm to Convert 4 byte Hex to 32 bit float
I really struggled hard to find out some sorts of algorithm to convert 4 hex bytes to 32 bit float for my requirement on some analysis of MODBUS protocol. I didn't find it and it tok me nearly 2 days to design this. Here is the algorithm..
float ModbusRead(byte id,byte msbAddress,byte lsbAddress,byte msbCrc,byte lsbCrc) { num=1.00; Serial.write(id); Serial.write(0x03); Serial.write((byte)msbAddress); Serial.write((byte)lsbAddress); Serial.write((byte)0x00); Serial.write(0x02);
Friday, August 8, 2014
Running particular application when Rspberry Pi boots up
While using Raspberry Pi you might not be interested to take a mouse and keyboard to run certain application when the Pi reboots. To avoid this many procedures are available . In this post i have used crontab to run a JAVA based application each time the Pi reboots. Actually crontab provides many more features.
Thursday, August 7, 2014
Monday, July 28, 2014
Power Over Ethernet (For Ethernet Connected Devices)
Power Over Ethernet is a widely used concept to power up remote devices like Arduino, Raspberry pi or any other embedded devices working on low voltage and power.There are ready made modules available in the market but are expensive so in this tutorial i will show you to make the cable modified to work for POE.
Saturday, June 21, 2014
Cheap Ethernet connection to Arduino using ENC28J60 module
While working on Ethernet projects with Arduino the basic hardware we require along with Arduino is the Ethernet Shield. But the problem is that in a constrained budget the buying one Ethernet Shield is not possible which leads to other options and a good one is ENC28J60 Ethernet chip by Microchip.This is not as smart as the Wiznet W5100 chip based Ethernet shields but are quite useful as those.This post i am going to write all about interfacing the ENC28J60 module to Arduino UNO as well as Arduino mini Pro.I have used EtherCard library for the coding to interact with the module.
Below is the wiring diagram for Arduino UNO.
Code:
Code:
#include <EtherCard.h> #define PATH "temp.php" byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; uint8_t ip[] = { 192, 168, 0, 8 }; // The fallback board address. uint8_t dns[] = { 192, 168, 0, 1 }; // The DNS server address. uint8_t gateway[] = { 192, 168, 0, 1 }; // The gateway router address. uint8_t subnet[] = { 255, 255, 255, 0 }; char website[] PROGMEM = "192.168.0.10"; static byte session; byte Ethernet::buffer[800]; uint32_t timer; Stash stash; float temp_R=0; int tempPinR = A0; String cont=""; int led = 9; int sw1 = A1; int sw2 = A2; int sw3 = A3; String sReply="";
Sunday, June 1, 2014
Room temperatuer logger using arduino and JAVA
This post is all about a temperature logger module using two sensors(LM35) and uses serial communication to log data to MySQL server. And it does so by using Arduino at the logger end and JAVA at the server.
The concept is so simple that the Arduino uses LM35 (providing analog output for measured temperature) ,which is connected to one of the analogIn pin of Arduino. The sketch burned to Arduino converts the read value from the pin to corresponding temperature. And it sends the data through the serial port.
At PC side a JAVA application runs which uses TxRx library for communicating with the serial port. The application reads the data from the serial port and acknowledged to Arduino. It then saves the red data to a database.
At PC side a JAVA application runs which uses TxRx library for communicating with the serial port. The application reads the data from the serial port and acknowledged to Arduino. It then saves the red data to a database.
Thursday, May 15, 2014
Control VLC Player using Android (Wifi Connected)
My first application of Android comes here.In my first tutorial on Controlling VLC using JAVA you can see that the VLC provides a Web interface from which it can be controlled and it also accepts certain commands.So that can be used to control the media player in Local Area Network using any programming language.This time its Android
Code:
MainActivity.Java
Code:
MainActivity.Java
package com.example.first_app; import java.net.Authenticator; import java.net.URL; import android.os.Build; import android.os.Bundle; import android.os.StrictMode;
4 Channel relay board using L293D
Many time it requires controlling relays to automate different things in projects.But thing is generally Relays are driven by either high voltage and requires high current but most of the embedded systems works at lower voltage and the constrain is they cant provide high current.
Saturday, February 22, 2014
Sending Message from PC through mobile using AT Commands over Bluetooth
AT Commands:
AT or attention are set of commands those are used to communicate with GSM modems.I am not going much about it as you can google it.I tried using the AT commands through Bluetooth which was successful and finally integrated it to JAVA so that I can send message through my mobile using an interface instead of hyper-terminal.Before getting it started check your mobile if it supports the commands or not by using Hyper-terminal or any serial port Software.
In the below codes i have used RxTx serial communication library that is free to use and my communication port was 'COM9' please check it for you and then changing it compile the code.
Main.java //Main GUI
package com.oksbwn.Y2014.Message_Mobile; import java.awt.Color; import java.awt.Dimension; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.*;
Saturday, February 8, 2014
Getting Facebook Access Token for JAVA applications
When for the first time i used facebook API in my java application using the library restFb i faced real trouble with the access token .For that i browsed a lot to get the token at last i was able.So to make it easy here are the steps to get the access token that is valid for 2 months.
Step:1
First of all create a facebook application and goto the application page.goto tools and click on APIExplorer in the menu as shown below select your application...
Step:1
First of all create a facebook application and goto the application page.goto tools and click on APIExplorer in the menu as shown below select your application...
Storing configuration data for JAVA applications
Many times it is required to store some configuration settings for your application so that it can use again and again from where it left.Or the application can start with some specific parameters.So the properties file can come handy in such requirements.
First lets write something to the properties file..
Code:
First lets write something to the properties file..
Code:
import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; public class App { public static void main(String[] args) { Properties prop = new Properties(); OutputStream output = null; try { output = new FileOutputStream("C:\\Alberto\\Config\\debug.properties"); prop.setProperty("stat","no"); prop.setProperty("mail", "oksbwn@gmail.com");
Controlling VLC media player using JAVA
Basically i was looking for a method to communicate with the VLC media player so that i can get the currently playing video on the player and my app can search the internet and get the details about the movie.For that i googled a lot and finally came to know that VLC has a web interface and i used that with my JAVA app to control and getting details of the movie.
First open the VLC and goto tools->preferences and check the All radio button. and navigate to the Main Interface and click on lua and there you have to set HTTP password (Otherwise u cannot access the web interface). Screenshot is given below.
Friday, February 7, 2014
Tuesday, February 4, 2014
Show movie details using JAVA
In this post i am going to post about using the anditson.com API to search for a movie online and display the results like a gallery as shown above using JAVA.anditson.com provides a good API which actually provides all data associated with a movie in JSON or XML format.I have used the XML format.Here are the codes...
Code to search online:
Code to search online:
import javax.xml.parsers.DocumentBuilder;
Thursday, January 30, 2014
A Tweet Gallery in JAVA
As the title says the above image is the screenshot of a tweet gallery that i have designed using JAVA and JAVAFX., to access the tweets i have used twitter4j library.Below are the codes to design the gallery.Also My-SQL database is used to store the tweets periodically and when clicked on view then it shows the latest 25 tweets from the database.
Sunday, January 26, 2014
MySQL database access using Python in Raspberry Pi
While working with Python in Raspberry Pi it might be useful to have a database access for your application or somewher it is required.Or may be as a beginner you would like to use MySQL with Python.Here i have compiled a post on how to use MySQL with Python...
First of all you have to install python-MySQLdb which interacts between the My-SQL database and the Python.So to install it in the Raspberry-Pi terminal type..
I have already installed so my screenshot is looking like this..after installing this nothing else is required..
Move to the desktop and open the Python IDLE.Remember don't open the IDLE 3 as it doesn't supports the MySQLdb.
Now in the prompt type
if it shows some error then the MySQLdb is not installed.If it is installed then it will show nothing.In the IDLE click on File and New Window this will open a new editor to write the python codes.
Editor...
Now lets you have a database dbase and user is root and PWD is pwd and has a table tab and some stored data.Here is my database snap...
Now in the editor write the following code and save it by pressing ctrl+s and execute it by pressing F5.It will show you the results in the IDLE shell.
Code:
First of all you have to install python-MySQLdb which interacts between the My-SQL database and the Python.So to install it in the Raspberry-Pi terminal type..
sudo apt-get install python-mysqldb
I have already installed so my screenshot is looking like this..after installing this nothing else is required..
Move to the desktop and open the Python IDLE.Remember don't open the IDLE 3 as it doesn't supports the MySQLdb.
Now in the prompt type
import MySQLdb
if it shows some error then the MySQLdb is not installed.If it is installed then it will show nothing.In the IDLE click on File and New Window this will open a new editor to write the python codes.
Editor...
Now lets you have a database dbase and user is root and PWD is pwd and has a table tab and some stored data.Here is my database snap...
Now in the editor write the following code and save it by pressing ctrl+s and execute it by pressing F5.It will show you the results in the IDLE shell.
Code:
import MySQLdb=MySQLdb.connect("localhost","user","password","database") curs=db.cursor() #tab is a table in the database curs.execute("SELECT * FROM tab") for reading in curs.fetchall(): print str(reading [0]) db.close()
Subscribe to:
Posts (Atom)