Category: Raspberry PI


Raspberry Pi Pico is a low-cost, high-performance microcontroller board with flexible digital interfaces.

Other Raspberry PI boards are SBC –  Single Board Computer which requires an OS on a SD card.

But PICO is a Microcontroller like Arduino.

RPI boards do not have ANALOG inputs , PICO has 3 ANALOG inputs.

Designed on RP2040 IC (Dual-core Arm Cortex M0+ processor flexible clock running up to 133 MHz)

, this PICO board has 26 GPIO pins including 3 Analog Inputs.

As such RP2040 HAS 30 GPIO pins including 4 Analog inputs, but on board the user is offered with only 26 GPIO pins including  3 Analog Inputs.

  • 264KB of SRAM, and 2MB of on-board Flash memory
  • Castellated module allows soldering direct to carrier boards
  • USB 1.1 with device and host support
  • Low-power sleep and dormant modes
  • Drag-and-drop programming using mass storage over USB
  • 26 × multi-function GPIO pins
  • 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM channels
  • Accurate clock and timer on-chip
  • Temperature sensor inbuilt
  • Accelerated floating-point libraries on-chip
  • 8 × Programmable I/O (PIO) state machines for custom peripheral support

https://www.raspberrypi.org/products/raspberry-pi-pico/

pico_pins

PICO can be programmed with C / C++ SDK or MicroPython.

In this blog, we work with MicrPython.

To start with Press & Hold the BOOTSEL button on board and connect the USB to Windows PC.

CONNECT

Release the BOOTSEL button to see PICO appear as a mass storage device RPI-RP2.

Image 1

Open the Device Manager , you see PICO under Portable Devices as RPI-RP2.

Image 2

Open the RP2 storage .

Double click on the INDEX.HTM file to visit the official PICO website.

Image 3

Image 4

Scroll down to click Getting started with MicroPython.

Image 5

https://www.raspberrypi.org/documentation/pico/getting-started/static/f70cc2e37832cde5a107f6f2af06b4bc/rp2-pico-20210205-unstable-v1.14-8-g1f800cac3.uf2

Here download the UF2 file , which is USB Flashing Format by Microsoft.

UF2 files can be opened and edited using a variety of Microsoft MakeCode editors.

To transfer a UF2 file to a microcontroller, developers plug their microcontroller into their PC’s USB drive. Their PC then recognizes the microcontroller as a FLASH DRIVE, allowing the developer to drag their UF2 file to the microcontroller and install their MakeCode program.

Image 6

Drag and Drop the UF2 file on to RPI-RP2.

Image 7

RPI-RP2 now disappears indicating Micropython installation is complete.

If you open the Device Manager , PICO appears as USB SERIAL DEVICE and a COM port is allotted.

Image 8

For GUI interface we use THONNY PYTHON.

Download and install Thonny Python

https://thonny.org/

Image 9

Open Thonny Python

Under Tools –> Options

click INTERPRETER

th1

Under Interpreter drop down select

MicroPython Raspberry Pi PICO   and select the COM port allotted to PICO.

PICO is listed only in the newer version of Thonny.

th2

Now click on the RED stop button to get the Interpreter CHEVERON 3 greater than symbol at the bottom.

You can try MicroPython commands here.

Image 10

To blink the on board LED let us start the coding under Editor.

First import PIN Class from machine module.

Functions are called modules in Micropython.

Then import sleep class from utime module for delay.

Create an led object which takes 2 parameters.First is the GPIO PIN , which is 25 where the inbuilt led is connected.

Second parameter to declare this pin as OUTPUT.

Then starts the never ending loop

while True:

After the colon you get an indentation space automatically.

This is equal to braces in Micropython.

Here we toggle the led and provide a delay of 1 second.

Image 11

Click File –> Save As

Image 12

You get 2 options to save.

Select Raspberry Pi PICO to save the file.

Image 13

Provide the filename as

main.py

Auto execution takes place only if the file name is main.py.

So it is a must to provide file name as main.py.

Image 14

Click on the green RUN button

Image 15

Now the LED on board blinks according to code.

C2[3]

To RESET the PICO back to factory condition

there is another UF2 file under Resetting Flash memory.

Download this nuke UF2 file.

Image 16

Press hold the BOOTSEL button and connect the USB to pc.

IMG_20210205_182142

Drag and drop the nuke UF2 file on to RPI-RP2 to erase flash memory back to factory condition.

There is no RESET button on PICO.

You can connect a RESET button between RUN and GND pin as shown below :

reset

video :

blog_image

7 HDMI display with capacitive touchscreen is now available with resolution 1024 x 600 pixels.

The touch panel supports up to 5 touch points. And it adopts  free-driver technology, no special requirement of drivers.

There is no need for  external power supply for the screen, it can be powered by USB port and HDMI port from Raspberry PI.

  • Operating Voltage: 5V
  • Operating Current: 160mA
  • Maximum Operating current: 1200mA  (with HDMI connection)
  • Refresh Frequency: 43Hz – 60Hz
  • Screen Resolution: 1024×600
  • Video Interface: HDMI
  • Supports Raspbian,Raspberry PI  OS ,5-points touch, driver free.

Previous models are TFT displays.TFT stands for the thin-film transistor, which is just another kind of liquid crystal display.One of the major shortcomings of using TFT is that it does not offer a good level of visibility.

This new display is IPS . In-Plane Switching

IPS panels seek to solve TFT panels’ issues of poor color reproduction and viewing angles. In this regard, IPS panels have largely succeed. Not only do they offer a higher contrast ratio (superior blacks), high color accuracy , but IPS panels also have very little color shift when changing the viewing angles.

Hence, with this technology, you can view the screen from much wider angles and sides without experiencing unwanted blurriness and grayscale.

The negative point about IPS panel is their poor response rates and lower possible refresh rates, IPS panels are generally not considered for competitive gameplay

WAVESHARE make is original

IMG_20200902_134558

On the back side left top is the HDMI connector.Below that is the micro USB socket for power and touch.This USB can be connected to one of the USB ports of RPI.

A mini slide switch is there for display ON / OFF.

IMG_20200902_134626

A HDMI cable , USB to micro usb cable and a HDMI micro converter ( used for RPI 4 models)

are provided with the display.

IMG_20200902_134723

Clone or Copy models similar to Waveshare are also available in the market.

Clone display has 2 micro usb sockets , one for power & the other for both power & touch.

IMG_20200830_151339

WaveShare original has EMI and ESD protection near the HDMI socket

IMG_20200902_134652

Also the original one has USB protocol translator, converting the touch signal into standard multi-points touch protocol to achieve smooth multi-points touch control.

IMG_20200902_134642

Before connecting the display to Raspberry PI , prepare the Operating System for PI.

Download the latest RASPBERRY PI OS ( previously called Raspbian) from

https://downloads.raspberrypi.org/raspios_full_armhf_latest

Use BALENO ETCHER software to write image on to SD card.Always use CLASS10 type micro SD card.

For this you need a card reader to plug SD card on to your PC.

https://github.com/balena-io/etcher/releases/download/v1.5.107/balenaEtcher-Setup-1.5.107.exe

Once the image is written on SD card , if you re plug the card reader to pc, you can see the BOOT partition . The ROOT partition is not visible on Windows machine.

Image 1

Right click on empty space and create a new TEXT document.Name it as ssh.txt

Then delete the .txt extension , so that only a file named ssh exists without any extension.

On next boot on RPI , the SSH is enabled and the file named ssh will be deleted automatically.

Next we need to modify the config.txt file to enable view on display.

Open config.txt file.

Image 2

Scroll to the end of file and add following commands.

Image 3

As we power the display from USB of RPI , we need to boost the current source capacity of USB port of RPI.

This is achieved by

max_usb_current=1

which makes USB current source to maximum of 1.2 amp

Setting a specific HDMI mode is done using the hdmi_group and hdmi_mode config.txt entries.

The group entry selects between CEA or DMT, and the mode selects the resolution and frame rate.

hdmi_group=2

hdmi_mode=87

To set a custom display mode we use 87 for mode.

HDMI output group is set to 2 which represents DMT (Display Monitor Timings, the standard typically used by monitors)

Then define a custom CVT  — Coordinated Video Timings

hdmi_cvt= width1024  height 600  framerate 60  aspect 6  margins 0  interlace 0 rb 0

width  1024 pixels

height 600 pixels

framerate 60 Hz

aspect 6 —  ratio  15:9

margins  0
0=margins disabled, 1=margins enabled

interlace  0
0=progressive, 1=interlaced

rb  0
0=normal, 1=reduced blanking

Setting

hdmi_ignore_edid to 0xa5000080

enables the ignoring of EDID/display data if your display does not have an accurate EDID. It requires this unusual value to ensure that it is not triggered accidentally.

HDMI_BOOST increases the amplitude and/or pre emphasis of the HDMI signal.
For long HDMI cables use value 7 or 11.

Save the CONFIG.TXT file.

Remove the SD card and plug it to RPI.

Connect HDMI cable between HDMI ports.

Connect the micro usb cable to touch port of display and the other end to one of the USB ports of RPI.

Use a power adapter of 5v and ampere more than 2 amps

IMG_20200830_151414

Switch on the power to see the display booting up to welcome screen of RPI.

TOUCH functions work without any installation of drivers.

Image 4

You can also set the SD card for auto connect with WIFI , and also you can install Match box keyboard for on screen keyboard.

Watch this video :

blog_image

Node-RED is an example of a flow-based programming model .NODE RED is a powerful tool for building Internet of Things (IoT) applications by simply connecting & wiring together of code blocks & carry out tasks.It uses a visual programming approach that allows developers to connect predefined code blocks, known as ‘nodes’, together to perform a task.

The connected nodes, usually a combination of input nodes, processing nodes and output nodes, when wired together, make up a ‘flows’. Flows consist of multiple nodes wired together, with output tabs linked to input tabs of the next node in the flow. Messages flow along the nodes carrying data from node to node.

Today there is a vibrant user and developer community, with a core group working on the Node-RED code itself and most developers contributing nodes or flows to the flow library.

 

Image 4

In this post we use Raspberry PI 4 as hardware with Rasbian BURST OS & demonstrate a flow to control an LED connected to a GPIO pin of RPI.

Node RED is PRE-installed in Raspbian operating system by default.

Image 1

 

I’m accessing RPI from my Windows machine over WI-FI.

Both RPI & Windows PC are connected over WIFI to same Router.XRDP is installed on RPI & from Windows machine access is through Remote Desktop.

You can check out my previous blog on how to do this.

https://alselectro.wordpress.com/2019/12/10/raspberry-pi-how-to-auto-connect-wifi-and-view-on-windows-laptop/

 

Image 3

Though NODE RED comes preinstalled with Raspbian , you need to update initially.

Before starting Node Red , open Terminal & type in this command :

sudo apt-get install build-essential

—  to ensure npm is able to build any binary modules it needs to install. npm is Node Package Manager for the JavaScript .

Next Run the  following command to download and run the script

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

This script will remove the pre-packaged version of Node-RED and Node.js if they are present &

install the current Node.js LTS release using the NodeSource.

It also installs the latest version of Node-RED using npm ,setup Node-RED to run as a service and provide a set of commands to work with the service

 

update1

This action will take around 10 minutes.

update2

 

Auto start on boot
——————–

If you want Node-RED to run when the Pi is turned on, or re-booted, you can enable the service to autostart by running the command:

sudo systemctl enable nodered.service

To disable the service, run the command:

sudo systemctl disable nodered.service

To start NODE RED  by clicking on NODE RED under Programming.As it starts running you can see an IP address link ending :1880  which is the default port of Nodered.

Once Node-RED is running you can access the editor in a browser.

Image 2

If you are using the built in browser on the Pi desktop, you can open the address:

http://localhost:1880.

I recommend using a browser outside of the PI and pointing it at Node-RED running on the Pi.

When browsing from another machine you should use the hostname or IP-address of the Pi: http://<hostname&gt;:1880.

You can find the IP address by running

hostname –I

on the Pi. In my case host name is 192.168.1.5 , so I open browser on Windows and type in :

http://192.168.1.5:1880

where 1880 is default port of NodeRed.

Now the NODE RED Window opens with colored NODES on the left side Palette.Center portion is the Flow Canvas where you create the flow by dragging in the nodes.Right side pane is for INFO & dEBUG MESSAGES.

Image 3

Scroll down the nodes to locate Raspberry PI.

rpi gpio  node is frequently used to control GPIO Pins of RPI , which has 2 options.

Image 11

 

One with the RPI icon to left of node is INPUT node (like button input) & the other with icon to Right is for OUTPUT node (like LED control).

Image 4

 

Input nodes allow you to input data into a Node-RED application or “flow”. They have at least one output endpoint represented by the small grey square only on their right side. You use input nodes to connect data from other services, for example the  Twitter, Google, serial, websockets or tcp nodes, or to manually input data into a flow using the inject node.

Output nodes allow you to send data outside of a Node-RED flow. They have a single input endpoint on their left side. You use output nodes to send data to other services, for example via Twitter, tcp, serial or email nodes, or to use the debug node to output to the debug pane

In this demo we control an LED connected to GPIO pin17 of RPI.

 

LED1

 

For this task we need an OUTPUT Node.

 

Image 5

Drag an Output Node to the canvas.

The output node with name PIN: is displayed with one RED triangle & a BLUE Circle over RPI icon.

The red triangle indicates that the properties are not yet set & the blue circle indicates that the node is not yet deployed to server.

Image 6

 

Double click on the Node to get PROPERTIES window.

As we have connected an LED at GPIO 17 (PIN 11) , select this pin.

Image 7

Select the type as DIGITAL OUTPUT.

Leave the Initial level of pin as LOW & provide a name as Red Led

 

Image 8

Click on DONE to see the RED Triangle disappear.

As we have not yet Deployed the node , the Blue circle remains.

Image 9

To feed a message we need an Input node like INJECT.

Drag and drop Inject node.It appears as timestamp node with a Grey button on left folloed by an Arrow.

 

Image 10

Double click on this Inject node to set properties.

Under PayLoad select String.

 

Image 11

Provide value of Payload as 1 & give a name as ON.

This is to inject 1 to RPI output node to make LED ON.

Click Done.

Image 12

Now drag on the small grey circle seen to the right of our ON inject node & connect to the RPI node Red Led.

The nodes for switching ON the LED are ready now.

Image 13

Next we need to create a node to switch OFF the LED.

Drag an input INJECT node again.

Image 14

 

Double click on this node and set the PayLoad String to 0.

Provide a name , like OFF.

Image 21

Connect the OFF node to Red Led node .

Now the FLOW is ready to be DEPLOYED.

Image 16

Click ON the red DEPLOY button on top right corner.

 

Image 17

The blue circles on Nodes disappear & you get Successfully Deployed message.

 

Image 19

Click on the Grey square button seen to the left of ON node.

This injects a String 1 to Red Led node , making the LED at gpio17 ON.

 

Image 20

 

IMG_20200110_151030

To make the LED OFF , click the grey button of OFF node.This injects string 0 , switching OFF the LED.

You can see the string o at the bottom of Red Led node when it receives the payload.

Image 22

Next drag a DEBUG node from Output list.

Image 23

No properties setting for this node.Just connect both the ON & OFF nodes to the

debug node (msg payload)

 

Image 24

At the right top click on the DEBUG icon to see the debug messages.

Clicking on the ON or OFF nodes will control the LED , as well display the debug messages.

Image 25

Next we shall add a BUTTON to control LED.

Remove the ON & OFF nodes we created earlier , by selecting the node and hitting Delete button.

Drag and drop an Input GPIO node from Raspberry PI list.

 

Image 27

Double click on node to set properties.

Select GPIO 13 , as we connect a button to this GPIO pin.

 

Image 28

 

IMG_20200110_164327

The LED is connected to GPIO 17  as shown below.

A 2 leg reset button is used , one end of button goes to 3.3v & the other end through a resistor to GND.

The junction point is connected to GPIO 13.

 

Image 20                    Image 30

Under properties select PULL DOWN , which applies an internal resistor to GND to the button.For safety we use an external resistor too.

Select Read initial state of pin & provide a name as Button.

Image 29

Connect the node to Red Led node & Click on Deploy.

Image 30

When the button is pressed a HIGH is applied to GPIO 13 , which in turn switches ON the LED ta GPIO 17.

 

Image 31

To import new NODES or to install DASHBOARD click on settings button next to Deploy button & select MANAGE PALETTE.

 

Image 8

To search for new nodes , you can click on NODES & download.

To install dashboard , click the install button & search for dashboard.

Select node red dashboard & install.

 

Image 9

 

Node-RED Dashboard is a module that provides set of nodes  to  create a live data dashboard.

To open the Node-RED UI, type your Raspberry Pi IP address in a web browser

followed by     :1880/ui

With Dashboard you can select your own nodes and create your own User Interface.

To access the settings file of Node Red

use command

ls –a

to list hidden files.

Then change directory to  .node-red

Here you can see the settings.js file where you can provide password for access to node red.

Image 40

 

VIDEO TUTORIAL :

blog_image

In Raspberry PI 3 & 4 the physical UART at GPIO14/GPIO15 is disabled.

In new machines the mapping is as follows.

/dev/ttyAMA0 -> Bluetooth
/dev/ttyS0 -> GPIO serial port   (referred to as the “mini uart”) disabled by default.

The powerful ttyAMA0 is assigned to Bluetooth & the limited frequency ttyS0 is assigned to UART.

Board pin 8 (GPIO14)  Tx
Board pin 10 (GPIO15) Rx

older Raspberry Pi it will point to the hardware UART and /dev/ttyAMA0

gg1

In this post , let us see how to enable UART and then overcome the Permission denied problem by swapping the ttyAMA0 & ttyS0.

denied

 

While connecting the GSM with RPI use level shifter, as the TTL level of PI is 3.3 volt & that of GSM is 5v.

The Tx of PI (physical pin 8) goes directly to Rx of GSM. As GSM accepts 3.3v as High, you can connect this straight .

But the Rx (physical pin 10) pin needs alevel shifter before connecting to Tx of GSM

A simple 1k resistor in series and a 2k2 to GND will solve the purpose.

IMG_20191228_154854

To enable the serial0 edit config.txt file using nano editor.

g1

Navigate to the end of file and add

enable_uart=1

ctrl+x & Yes to save the file

g2

use command

ls –l /dev

to read the devices.You can see serial0 is now enabled and mapped to ttyS0.

Image 4

Open picocom to communicate with GSM

picocom –baud 9600 /dev/ttyS0

Permission is Denied.

denied

 

You can change permissions with sudo chmod command.But on next reboot this will change.

Also assigning groups dialout & tty to user PI does not help.

Image 2

In Raspberry Pi , you can use the serial port as a terminal to log in.
Even if you don’t have a network connection,you can connect to another computer via their serial ports and run a terminal software like putty  on the other computer to get a login prompt.

By default the Raspberry Pi uses the serial port for this “console” login
and via a software service called “getty”.

if we want to use the serial port to get data from a GPS or GSM, we need to disable
the console login so that gsm/gps alone get control of the port.

use the following commands

sudo systemctl stop serial-getty@ttyS0.service
sudo systemctl disable serial-getty@ttyS0.service

First command is to STOP the service of getty & the second one disables it.

Image 5

 

Finally Remove the console service by editing cmdline.txt

 

g4

 

remove the line:

console=serial0,115200

and save , reboot for changes to take effect.

 

g5

 

 

Image 6

 

To use BLUETOOTH add the following line to the /boot/config.txt

sudo nano /boot/config.txt

 

g7

Add this line at the end

dtoverlay=pi3-miniuart-bt

 

g8

Now mini uart is assigned to Bluetooth function.

 

g9

After reboot you can check the devices

ls –l /dev

to see serial0 is assigned to ttyAMA0 & serial1 to ttyS0

 

Image 82

Install putty serial terminal .

 

g10

 

 

g11

open putty

Select SERIAL & feed in host as

/dev/ttyAMA0

& BAUD RATE 9600

 

g12

 

pUTTY Terminal opens where we can test the GSM AT Commands.

 

g13

Now the UART is mapped to ttyAMA0 as in older machines of PI and old python codes will work without any change.

Video support :

blog_image

 

 

TITLE_WIFI

 

In this article we will explore the ways to auto connect Raspberry PI to WIFI and control it from a Windows machine.

In this demo I use RASPBERRY PI 4 2 GB board , but the method applies to all versions with WIFI ,

RPI 3 B , B+ &  RPI Zero W.

There is no need to connect any Ethernet cable to PI .The keyboard , display of Windows machine are used to control RPI. This is called HEADLESS MODE of operation.

This post will get you up and running with a Raspberry Pi, connected to your WIFI network and accessible over SSH, without ever needing to connect anything to it, besides power source.

RPI 4 comes in 3 variables with 1GB , 2GB  or 4GB RAM. This has 2 USB 3.0 & 2 USB 2.0 ports , a Gigabyte Ethernet port & 2 micro HDMI 4k support ports.

The power cable to be used is C type which can handle more current .

To start with download the latest Raspbian OS image from the official website:

https://www.raspberrypi.org/downloads/raspbian/

Use CLASS 10 Micro SD card of more than 16GB memory.

A card reader can be used to plug in the SD card on to the Windows Laptop.

Image102                   Image104

 

To burn the OS image use ETCHER software .

Download it from here :

https://www.balena.io/etcher/

 

Image 101

 

You now have the latest Raspbian image ( BUSTER at the time of this blog) which is ready to boot, but not yet ready to fully work headless!

Remove the card reader with SD card and plug it again .The Windows system can display only the BOOT partition . The ROOT partition is not visible.

Image 1

 

Prepare to Connect WIFI

To make the Pi connect to your Wifi access point at first boot, store the wifi connection details on the Pi’s boot drive.

Following to be done on Windows system.

Under boot partition of SD card , you need to create a file named wpa_supplicant.conf.

Before this , click on View & put a tick mark against File Name Extensions.

This enables to view the extension of filenames.

 

Image 2

Right click on empty space and create a new Text document.

Image 4

Rename the text document to  wpa_supplicant.conf.txt.

Image 5

 

Image 6

Double click the file to open in Notepad.Remember , the file name is now with .txt extension , so that it is open with Notepad.Later you need to delete this .txt extension .

Visit this official site to copy and paste the WIFI code.

https://www.raspberrypi.org/documentation/configuration/wireless/headless.md

The 2 letter Country Alpha-2 code is important and can be known from this wiki link :

https://en.wikipedia.org/wiki/ISO_3166-1

Now enter the 2 letter Country code & then your WIFI SSID name and password.

Image 7

If you want to connect with more than 1 SSID , wherever available , you can use the

PRIORITY setting as shown below.

Image 8

Save the file.

Right click to rename & remove the .txt extension.

 

Image 9

On First Boot the contents of this file will be copied to the relevant etc file location , WIFI enabled and joined to the SSID credentials given.

Finally this wpa_supplicant.conf file will be deleted automatically.

ENABLE SSH

By default, a clean Raspbian image will have Secure SHell SSH disabled. You need to enable SSH at first boot.

To do this , right click on empty space on BOOT section of SD card and create an empty text document ssh.txt

Rename it to delete the .txt extension.

On first boot SSH will be enabled and the file will be deleted automatically.

Image 105

 

Now remove the SD card and plug it on to Raspberry PI.Power up the PI using proper adapter , a power source of 5v 2.4amp required.

Allow some time to boot up and to auto connect with WIFI.

Following image is the scenario setup now.

 

TITLE2

A Router connected to Internet Service Provider acts as an Access point .My Windows Laptop is connected to this Router over WIFI.

Now my Raspberry PI also joined the same network.

The Gateway IP of my Router is 192.168.0.1

The Router will assign IP address to its clients as and when connected by DHCP server.

To verify , whether RPI has joined the network , use PUTTY Software

Image106

PuTTY is an SSH and telnet client

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Open PUTTY and select SSH .

Enter HOSTNAME as  raspberrypi.

Click OPEN

Image 10

Now you can login using standard Raspberry PI credentials

username : pi

password : raspberry

Image 11

You get the Raspberry PI home prompt.

To know the IP ADDRESS allotted to PI type in

hostname -I

Image 12

 

To know the Gateway IP of Router

route –n

 

Image107

You can type in this Gateway IP on to your Browser to access the Router settings.

 

Image108

Under DHCP –> DHCP Clients list you can see the list of CLIENTS

You can see the raspberrypi as a client with MAC address and an IP allotted.

This IP is allotted by the DHCP Server, which allots accordingly on first come first basis.

It means , if you shut down RPI and connect again the IP may not be the same.The IP allotted is DYNAMIC.

Image 109

To make it STATIC , copy the MAC address of PI (as seen in above screen shot)

Click on ADDRESS RESERVATION under DHCP of Router settings.

Click ADD NEW…

Image 110

Paste the MAC address and the IP address of RPI you wanted to make it permanent.

This IP should fall in Gateway IP 192.168.0.1 , where the last octet only is changed.

Image 111

Now the address is made STATIC and will be same on every boot.

Next  to view RPI on windows we need to install Remote Desktop protocol client XRDP on RPI

rdp1

sudo apt-get install xrdp

to start installation of xrdp.

Image 13

On Windows machine , RDP server is installed by default on WIN7,8 & 10.

RDP is proprietary of Microsoft.Just ensure that under advanced system setting,

Remote Assistance is allowed.

r1

Open the Remote Desktop connection on Windows.

Image 14

Type in computer name as rapberrypi & Connect.

Image 28

 

 

Image 29

Login window will appear.Here under Session select Xorg ( previously it was called sesmanager)

Image 38

username as pi & password raspberry

Image 30

Now you can see the Raspbian welcome screen on Windows machine.

Image 31

Image 32

 

Image 33

video tutorial :

 

blog_image

 

VIDEO Demo :

 

Relay module boards play an important role in Home automation projects. Generally we connect the load ( fan,light,etc…) to be controlled through the Relay contacts . While is the relay is controlled ON/OFF , IN TURN the load is controlled through the relay contacts.

Different types of relay modules are available .

In this post we explore the best Relay module suitable to use with Raspberry PI.

image

 

Relay modules are available in 12v & 5v .The best one for RPI is 5V Relay Module with Opto coupler drive.

This type of relay boards have opto coupler & NPN transistor to control the relays. Each relay is controlled by an opto+transistor combInation.

image

 

When a LOW is applied to INPUT , say IN1 , the photo diode inside optocoupler conducts which in turn activates the photo transistor inside the opto.

The NPN TRANSISTOR after the opto coupler is triggered which in turn switches ON the relay.

 

image

 

On board a Jumper is provided between JD_VCC & Vcc .While the jumper is ON & Vcc is provided with 5v , the board operates normally. When LOW is at input , the relay is ON. The problem arises when connected to RPI whose GPIO pins are at 3.3v level.

When a HIGH is applied from RPI , THERE WILL BE POTENTIAL DIFFERENCE OF 5V – 3.3V = 1.7V which causes the board relay to chatter or malfunction.

So while using with Raspberry PI always remove the jumper & provide 5V to JD_VCC   & 3.3V to Vcc.

Both these voltages can be directly connected from the RPI itself. No separate power source required for Relay board. In RPI 3.3V is capable of only 50 milli amp sourcing current.

This 3.3v is connected to Vcc of Relay board which drives only the photo diode of opto coupler.So  a small current is enough.

The 5V rail of RPI is capable of sourcing much more current. It depends on the power adapter used for RPI less the current consumed by the RPI itself . 500MilliAmps can be easily sourced at this 5v point of RPI.

Let us now connect PI with 4 channel relay board.

RELAY BOARD     RPI

JD_VCC              5v

VCC                  3.3V

IN1                   Pin 32

GND                 GND

Ethernet cable is connected between PC & RPI,&  PI is accessed from PC through SSH client PUTTY

Refer my previous blog on how to access PI from PC

https://alselectro.wordpress.com/2018/07/24/how-to-connect-raspberry-pi-to-laptop-direct-network-link-method/

 

image

 

LOG IN using default user name pi &password raspberry

To test python commands start the python interpreter by typing command

python3

By default, Raspbian Stretch version  uses Python 2. However, versions 2 and 3 come installed by default. We just have to make 1 minor change so that the Pi uses Python 3 whenever we type python into a terminal.

In a terminal window, enter the following command:

nano ~/.bashrc

Scroll down to the bottom, and add the following command to the file:

alias python=’/usr/bin/python3′

Exit out of nano by pressing ctrl+x, press the y key when prompted if you want to save the file, and press the enter key.

you can  run the contents of the .bashrc script by entering:

source ~/.bashrc

Now check the version of Python

python –version

Just type in python to get the INTERPRETER  symbol >>>

Now you can test python commands one by one.

 

image

 

First import RPi.GPIO module

import RPi.GPIO as GPIO

Functions are called Modules in Python. Note the casing of letters used RP in capitals & i in small case .We also use alias name GPIO , so that further in code you just need to mention GPIO instad of RPi.GPIO

To specify which pin configuration you are using type

   GPIO.setmode(GPIO.BOARD)

There are two ways of numbering the IO pins on a Raspberry Pi within RPi.GPIO. The first is using the BOARD numbering system. This refers to the pin numbers on the P1 header of the Raspberry Pi board. The advantage of using this numbering system is that your hardware will always work, regardless of the board revision of the RPi. You will not need to rewire your connector or change your code.

The second numbering system is the BCM numbers. This is a lower level way of working – it refers to the channel numbers on the Broadcom SOC. You have to always work with a diagram of which channel number goes to which pin on the RPi board. Your script could break between revisions of Raspberry Pi boards.

To detect which pin numbering system has been set (for example, by another Python module):

mode = GPIO.getmode()

The mode will be GPIO.BOARD, GPIO.BCM or None

 

Physical pin 32 is set as OUTPUT using

GPIO.setup(32,GPIO.OUT)

Pin 32 is initially made HIGH so that relay is OFF

GPIO.output(32,GPIO.HIGH)

To make the Relay ON , set pin 32 to LOW

GPIO.output(32,GPIO.LOW)

At the end any program, it is good practice to clean up any resources you might have used.

To clean up at the end of your script:

GPIO.cleanup()

Note that GPIO.cleanup() also clears the pin numbering system in use.

Now let us connect other Relay inputs to RPI

PIN 36 to IN2

PIN 38 to IN3

PIN 40 toIN4

Open NANO editor by typing

sudo nano relay.py

Feed in the following code.

Note the usage of Indentation for try block.

You can press TAB key to introduce blank space indentation whichis equal to braces in PYTHON.

 

——————————————

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(32,GPIO.OUT)
GPIO.output(32,GPIO.HIGH)

GPIO.setup(36,GPIO.OUT)
GPIO.output(36,GPIO.HIGH)

GPIO.setup(38,GPIO.OUT)
GPIO.output(38,GPIO.HIGH)

GPIO.setup(40,GPIO.OUT)
GPIO.output(40,GPIO.HIGH)

# main loop

try:
      GPIO.output(32,GPIO.LOW)
      print "First Reay ON"
      time.sleep(2)
     GPIO.output(36,GPIO.LOW)
     print "Second Relay ON"
     time.sleep(2)
     GPIO.output(38,GPIO.LOW)
     print "Third Relay ON"
     time.sleep(2)
     GPIO.output(40,GPIO.LOW)
     print "Fourth Relay ON"
     time.sleep(5)
    GPIO.cleanup()
    print "Good bye!"

except  KeyboardInterrupt:

print(“QUIT”)

GPIO.cleanup()

————————————————

Press CTRL+X  to quit & press Y to save the file.

To execute the file

python relay.py

The Relays will be switched ON one by one & finally all Relays will be OFF , according to code.

 

IMG_20180922_150146

 

The single channel relay boards are  different. Some boards have OPTO Coupler & some

do not have opto.

    r1                r2

The board with opto is HIGH enabled. A HIGH is required at IN to switch ON relay.

The board without OPTO is LOW enabled . A LOW is applied at IN to switch ON Relay.

Jumper is not seen on these single relay boards.

Always use 3.3v to Vcc in these single channel relay boards.

 

blog_image

This post is on interfacing GSM with Raspberry PI 3  B or B+.

UART is commonly used on the Pi as a convenient way to control it over the GPIO, or access the kernel boot messages from the serial console (enabled by default).

It can also be used as a way to interface GSM / GPS /Arduino / ESP8266, etc with your Pi.

Be careful with logic-levels between the devices , for example the Pi is 3.3v and the GSM is 5v.

 

IMG_20180719_121323

 

In the previous versions of PI GPIO Serial port is mapped to /dev/ttyAMA0

(COM1 equivalent is found on pins 14 and 15 of the GPIO header and is called /dev/ttyAMA0  )

But in PI 3 B or B+ this hardware port has been utilized for the BLUETOOTH Functionality.

/dev/ttyAMA0 is a hardware , high performance serial port (uart) & used for the Bluetooth

A second port is partly software /dev/ttyS0 & is assigned to GPIO Serial port.

So , the ports on a Raspberry Pi 3  are

——————————————————–

/dev/ttyAMA0 -> Bluetooth
/dev/ttyS0 -> GPIO serial port   (referred to as the “mini uart”).

————————————————–

Thus on a Raspberry Pi 3 serial0 will point to GPIO pins 14 and 15 and use the “mini-uart” ( /dev/ttyS0).

On older Raspberry Pi’s  it will point to the hardware UART and /dev/ttyAMA0.

Image A

 

To start with write the  RASPBIAN image OS on a class 10 memory card using ETCHER

 

etcher

Use the SD card on RPI 3 & log in

To know the Serial ports enabled  , type in

cd /dev   & then  ls –l

 

Image 2

You can see only the ttyAMA0 is enabled & not the  mini uart  ttyS0

Image B

The GPIO serial port is disabled by default. In order to enable it, edit config.txt:

$ sudo nano /boot/config.txt

and add the line (at the bottom):

enable_uart=1

Reboot for the changes to take effect.

Image 5

 

Image 7

 

Image 8

Restart the Putty SSH

Now check the   cd /dev  ,  ls –l    again

You can see both the ports enabled. Note that this can be done through raspi-config also.

Image 3

Let us connect the GSM with PI now.

RPI-GSM

 

The logic levels of PI are at 3.3 volts & it is risky to connect directly with a 5v level GSM pin.

The Tx pin (pin 8 , GPIO14) of PI can be directly connected to Rx of GSM. As GSM accepts 3.3volt level as high , this connection is straight without level shifting.

However the Rx pin (pin 10, GPIO 15) of PI cannot be connected directly to Tx of GSM.

A simple level shifter using a signal diode 1N4148 &  a 10k resistor is used in between as shown below

LOGIC LEVEL SHIFTER

LEVEL1

When the level at GSM Tx is LOW , the diode is forward biased & the Rx of PI gets LOW.

When the level at GSM Tx is HIGH ,the diode is Reverse biased & the 3.3v is available at Rx of PI through the resistor.

A separate power source 12v 1 amp is required for GSM , and the GND pins of PI & GSM are made common.

Be cautious while connecting with PI pins , as any wrong connection will render the PI defective.

After powering the GSM wait for the network. The network LED blinks fast initially  & after getting Network it blinks slowly.

You can also call to the SIM number used on the GSM to get a ring back tone.

Now the set upis ready.

Let us install  a Serial monitor called picocom on PI to test the AT commands.

 

Image 4

Start the picocom with baud rate 9600 & at portttyS0

picocom –baud 9600 /dev/ttyS0

Note the double hyphen before baud .

Image 9

You get Terminal Ready

after which you can type in AT to get an OK response.

If you cannot seewhat you type,or if no response then check the GSM for network &also check the port name you’ve typed.

It must be /dev/ttyS0 .      S is capital letter & then zero.

Now you can make a call using ATDxxxxx; command , terminate a call using ATH

Send SMS using AT+CMGF=1 , & test other AT commands

 

Image 11

 

Now let us use PYTHON to make a call.

Open a file named dial.py using

sudo nano dial.py

 

Image 12

Type in following code & then CTRL+X , to exit & Yes to save.

Image 13

While using AT command inside Python code , notice the usage of carriage return

\r  after each command    like ATDxxx; \r

To execute the file

python dial.py

You can see the number being called & then hangs up using ATH command.

Image 16

Now let us create a python code for sending SMS.

Notice the usage of  double quotes for sending AT commands

Also, note that single quotes used if the AT command needs to send double quotes

as in AT+CMGS command

Image 14

 

To execute type in

python sms.py

You can see the sms being sent to the phone number used in code.

Image 17

Support VIDEO :

 

 

blog_image

In my previous post I’ve explained the method  of connecting Raspberry PI with  Laptop through Ethernet.

https://alselectro.wordpress.com/2017/02/17/raspberry-pi-3-how-to-connect-with-your-laptop/

At times , the PI is not recognized , or unable to contact over SSH in this method.

Let us see the DIRECT NETWORK LINK method In this post which is 100% reliable.Cons is that network internet is not shared.But this is not an issue , as PI3 is WIFI capable through which you can connect to internet.

IMG_20180724_110102

 

To start with , place the SD card ( class 10 type recommended ) with Raspbian OS on to a Card Reader

 

Image 1

 

The card will be shown as boot drive.Open it.

Under View , un tick the option “ File Name Extension”

 

Image 2

Now Right click on empty space & create a new text document.

Rename it to ssh & save it.

Now a file named ssh is created without any file extension

When the card is now used on RPI, on first boot the OS will look out for the ssh file name.If it finds one , it enables secure shell & then delete the file named ssh.

This is how SSH is enabled in a Headless mode operation of RPI.

Image 3

Place the SD card on to PI & power it up.

Now Open Network& Sharing center on your Windows PC.

Image 4

 

Connect the Ethernet port of RPI to the Ethernet port of your PC using a STRAIGHT RJ45 Cable.

An Unidentified Network is created for the Ethernet adapter where PI is connected .

 

Image 7

 

Click on the Network connection type ,( here mine is WIFI.)

Click properties

 

Image_a

 

Under SHARING Tab un tick the options so that Network sharing is DISABLED.

 

Image_b

 

Click on the ETHERNET connection & then Properties on next window.

Double click Internet Protocol 4 & ensure that DHCP is enabled i.e, Obtain IP address automatically is selected.

Image 8

 

For a network link to work between two computers they need to be using the same address range.
The allowable address range is determined by the subnet mask.

255.255.0.0  means all octets in addresses should be same except for the last two in the IP address,otherwise they will be filtered.

Most PCs connected directly to another computer will allocate an IP address in the range 169.254.x.x ( with subnet mask of 255.255.0.0)

For RPI to be able to communicate through the direct link it needs to have a fixed IP address in the same address range 169.254.x.x

We can set this in the cmdline.txt file

To know the IP allotted to the ETHERNET adapter

Open Command Prompt ,CMD

Type in ipconfig /all

Image 9

Scroll down to find the IP under Ethernet adapter.

Here it is 169.254.192.43

which is the Gateway IP of Ethernet adapter.Any device connected to this port should have the IP in range 169.254.192.x

As we’ve connected the PI to Ethernet adapter  let us assign the IP toPI as

169.254.192.150

Note that the last octet can be anything up to 255.

Image 10

The static IP to PI is assigned as follows :

Switch off power to PI ,remove SD card & place it on a card reader.

Open cmdline file found in the SD card

Image 11

Move to the End of file.

Please note that you must not hit Enter .

Just at the end type in

ip=169.254.192.150

Image 12

 

Image 13

Save the file .Remove SD card from card reader & plug it to PI & power it up.

Let us use the free SSH Client PUTTY  to log intoPI.

Open PUTTY &  under Session , type in the IP address 169.254.192.150

Ensure that SSH is selected.

 

Image 14

 

Click open

Now you get the LOG IN window of PI

login as pi & password : raspberry

 

Image 15

Now ,let us see how to log in Graphical user interface.

For this a XMING X Server is required.

Download XMING from here

Install XMING & start the server.

Image 16

 

Image 19

Open Putty & as done previously enter the IP address 169.254.192.150

Under SSH click X11

& then Tick mark Enable X11 forwarding.

 

Image 17

Click Open to get the login window of PI.

To get Graphical interface , type in

startlxde

Image 18

Now you get the graphical screen

To get internet access :

Under  SYSTEM TOOLS  click LXTerminal

Image 20

Type in

sudo raspi-config

Image 21

 

Select Network Options

Image 22

Select WI FI

Image 23

Then enter  SSID of your WIFI to connect with

 

Image 24

 

Provide the password for thee SSID

Image 25

 

Hit FINISH

Image 26

Now you get the internet accesswhich can be tested by

sudo apt-get update.

 

Image 27

VIDEO DEMO  :

 

blog_image

Generally Raspberry PI is connected to a Router as an individual computer.In case you do not have access to your Router you can very well connect PI to Laptop through an ETHERNET STRAIGHT Cable.

The available RJ45 cable in the market is mostly STRAIGHT cable & not CROSS OVER one.

Before connecting the PI to Laptop , open your Network & sharing center & click on your Internet connection.Mine is on Wireless Network

 

Image 4

On the next screen click on the  properties button.

 

Image 5

Under SHARING tab Tick mark “Allow other network users…..”

Click OK to enable Network SHARING.

Image 6

Now let us enable SECURED SHELL – SSH on Raspberry PI OS , so that it can be accessed over network.

This can be done by connecting RPI to a HDMI TV & a keyboard.

Under terminal open RASPI-CONFIG & enable SSH under Advanced options.

But in this post I consider a Headless mode , presuming that you do not have access to a TV or keyboard.You need a CARD READER for this purpose.

Place the SD card with Raspbian OS on to the card reader & plug it to ypur laptop.

Note down the Drive letter allotted.Here it is I:\  in my case

 

Image 1

Run CMD & type in following

echo >I:\ssh

Now a file named ssh without any extension is created under \boot.

Image 2

 

Image 3

While PI is booted up then , it looks out for the file named ssh.

If it finds one , it enables SSH & then deletes the file you created.

This is how SSH is enabled in the new Raspbian OS.By default SSH is disabled in new OS for security reasons.

Plug the SD card on to PI & connect the ETHERNET cable to Laptop’s RJ45 slot.

Power up the PI to see a new Unidentified network .

Image 7

Click on that new Local Area Connection that appears & then click properties.

On the next screen , double click on Internet Protocol Version 4(TCP/IPv4)

 

Image 8

Now you see the IP address of the new Network created.

Here it is 192.168.137.1 which is the GATEWAY IP of the new Network.

PI will be allotted IP within this range 192.168.137.xxx

Image 10

To know the IP of RPI we make use of ADVANCED IP SCANNER

Download from here & install the scanner

http://filehippo.com/download_advanced_ip_scanner/download/a518016bdff73f05b5f25826e519a493/

Open the IP Scanner program & type in the Range to scan as 192.168.137.1 to 192.168.137.254

Image 11

Click on the scan button.

The IP scanner will detect the Raspberry PI & displays its IP along with host name & MAC address.

The host name is

raspberrypi.mshome.net   & the IP is

192.168.137.240

Image 12

You can use either the host name or the IP to access the PI.

We make use of an X Forwarding software called MOBAXTERM for a Graphical Interface.

You can use XMING server , but a separate SSH client like PUTTY is needed for that.

MOBAXTERM is a standalone freeware with an inbuilt SSH Client.

http://mobaxterm.mobatek.net/download-home-edition.html

Download the X Server

Image 13

Fire up the MobaXterm_Personal application.

Image 14

Click on SESSION & then SSH

Image 15

 

Under Remote Host type in the host name of RPI   raspberrypi.mshome.net

 

hostname

or you can use the IP address of PI we obtained from IP Scanner earlier.

Image 16

Now you get the login window.

Login username is pi & password is raspberry

Image 17

 

Now you are logged into Raspberry PI & you get the ~$ prompt

Image 18

 

To open Graphical interface , type in

startlxde

 

Image 19

 

You get a warning message SSH is ON .

Image 20

Click OK to see the DEBIAN SWIRL desktop.

 

Image 21

 

Image 22

 

Image 24

 

Image25

 

To enable WIFI & internet access , watch this video :

 

 

cooltext753793315  cooltext753790696

 

 

TOUCH screen LCDs are now available for use with Raspberry PI.

7 Inch LCDs work straight from the box as soon as you plug it onto your PI.No driver is required , but the touch response is poor & screen width is not full.

This post walks you through the steps of installing proper Drivers for touch to work smoothly & also installation of virtual keyboard is introduced.

The 7 inch LCD used here has a resolution of 800 x 480 pixels & the screen is Capacitive Touch.

HDMI interface is provided for Display &  USB interface for touch control. Both the HDMI & USB cables are provided in the box.

Connect the HDMI cable to the HDMI port of Raspberry PI & THE USB cable to any one port of the RPI.Slide the mini switch to ON position.

Provide a 5v 2Amp power source to the RPI , no separate power is required for the LCD

Image 2

 

7in_1    7in_3

 

Connect the RJ45 cable from the Internet providing Router to the RJ45 jack of Raspberry PI.In case of PI3 also this internet connection is a must for driver download & setup.Later you can switch on the WIFI on PI3 to connect with internet.

Insert the micro SD card with the latest RPI3 RASPBIAN Image on to the PI & switch ON the power.

You can see the initial screen is not Full screen. But interestingly , the touch will work.

Image 3

 

step 1 : CONFIG.txt editing to get FULL Screen Display :

To get the full screen display , you need to edit the CONFI.TXT file inside /boot folder.You can remove the SD card & plug it to PC using a card reader.

Open the folder & look out for the CONFIG.TXT file .Open this file using Wordpad or Notepad++.

Scroll down to the end of the file & append these lines :

Image 4

 

Setting max_usb_current=1 sets the available current over USB to 1.2A (default is 600mA)
This can help if you have a decent power supply (2A, at least) and need to power the external Touch screen display.

For supporting HDMI modes that aren’t from the official CEA/DMT list of modes
use  hdmi_mode=87

& then define the CVT – Coordinated Video Timings

The  hdmi_cvt 800 400 60 6 0 0 0
defines the timings of the component video signal

hdmi_cvt=<width> <height> <framerate> <aspect> <margins> <interlace> <rb>
width        width in pixels
height       height in pixels
framerate    framerate in Hz
aspect       aspect ratio 1=4:3, 2=14:9, 3=16:9, 4=5:4, 5=16:10, 6=15:9
margins      0=margins disabled, 1=margins enabled
interlace    0=progressive, 1=interlaced

 

Save this changes.Remove the SD card & plug it to RPI.

On rebooting you can find the FULL SCREEN display , but sadly the TOUCH performance will degrade. The touch selection will not be the one you insisted on touch.

To solve this problem you need to install the drivers.

 

step 2 : TOUCH DRIVER DOWNLOAD & Preparation

To install the Drivers , open the browser on PI & browse to

http://www.waveshare.com/wiki/5inch_HDMI_LCD

Scroll down to the driver section & download the driver which says

LCD-show-160811.tar.gz

http://www.waveshare.com/w/upload/3/3d/LCD-show-160811.tar.gz

driver

 

Click on the link to Download.

By default the tar file will be downloaded to  /root/Downloads

down_root

Using FILE MANAGER locate this folder & copy the downloaded tar file.

Now paste this file under /home/pi/Downloads

Right click the file & click on Extract Here..  to unzip the file.

down_2

 

down_3

Now you can see the unzipped folder.

Copy the PATH to this folder or note down the path , as we need it to install from within the Terminal.

unzip2

 

step 3 : DRIVER INSTALLATION

 

Open the Terminal & change directory to the PATH copied as in above step.

The path is  /home/pi/Downloads

Note the capital D in Downloads , as Linux is case sensitive.

To list the contents use ls  command

The list will display the folder LCD-show which contains the driver we need.

 

lcdshow1

Change Directory to LCD-show.

ls to list the contents

LCD-800×480-show  is the driver we need to install.

 

lcdshow2

To install use the command  dot forward slash LCD7-800×480-show

  ./LCD7-800×480-show

lcdshow_ins

The RPI will Reboot automatically & displays Full Screen.

Now try the TOUCH Functionality.It will be breeze to use the touch now, after driver installation.

 

step 4 : VIRTUAL KEYBOARD Installation

Now is the time to install the virtual keyboard .This avoids the physical keyboard & is a must for a touch screen.

Under Terminal type in

sudo apt-get install matchbox-keyboard

The keyboard installation starts.

When prompted , enter y to continue.

 

key2

Once the installation is over you can see the KEYBOARD under Accessories.

keyboard

 

If the KEYBOARD Icon is not seen under Accessories , click on

Preferences —> Main Menu Editor.

pref1

Under Main Menu Editor , put a tick mark against KEYBOARD.

A reboot is required.

pref2

Now open the KEYBOARD & enjoy.

keyboard2

 

Watch this demo VIDEO :

 

5 inch TOUCH SCREEN for RPI :

http://www.alselectro.com/7-inch-touch-screen-for-rpi–hdmi.html

 

cooltext753793315    cooltext753790696