ArduPi Library: Using Arduino Code on Raspberry Pi, Exams of Cyberlaw and Internet Law

An introduction to the ArduPi library, which allows Raspberry Pi users to write programs as if they were using an Arduino. The library includes conversion functions for serial port communications, I2C and SPI protocols, and GPIO pin control. The document also covers the connection bridge, its drawbacks, and how to install and use the library.

Typology: Exams

2019/2020

Uploaded on 05/23/2020

unknown user
unknown user 🇮🇳

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to
ArduPi
Prof. Jignesh Patoliya
Sr.Asst. Professor, EC Department
CSPIT , CHARUSAT , Changa
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download ArduPi Library: Using Arduino Code on Raspberry Pi and more Exams Cyberlaw and Internet Law in PDF only on Docsity!

Introduction to

ArduPi

Prof. Jignesh Patoliya

Sr.Asst. Professor, EC Department

CSPIT , CHARUSAT , Changa

Email:- [email protected]

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Introduction

 ArduPi is a C++ library that lets you write programs for

Raspberry Pi as if you were writing an arduino program.

 The library provides several conversion functions which

allows to use Raspberry Pi with the same code used in

Arduino:

 Serial Port Communications

 I2C Protocol

 SPI Protocol

 GPIO pin control

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Connection Bridge

 The idea behind the Raspberry Pi to Arduino shields

connection bridge is to allow to use any of the shields, boards

and modules designed for Arduino in Raspberry Pi.

 The connection bridge is developed by

www.cooking-hacks.com

 It includes also the possibility of connecting digital and

analog sensors, using the same pinout of Arduino but with

the power and capabilities of Raspberry.

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Drawback

 The ArduPi library was prepared for a Connection Bridge which

allows Arduino Shields to be used directly with Raspberry Pi.

 Problem?

 The Connection Bridge is not available with the Raspberry Pi

 Raspberry Pi does not have ADC pins (needs extra interfacing)

 The GPIO numbering is according to Connection Bridge

 Solution?

 Prepare a PinMap according to the Connection Bridge

 Enjoy the library without using Analog Commands.

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Conversion Pin Map

Arduino Pin RasPi Pin

0 10

1 8

2 12

3 16

4 18

5 22

6 7

7 11

Arduino Pin RasPi Pin

8 13

9 15

10 24

11 19

12 21

13 23

SCL 5

SDA 3

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

How to Install Library Files?

 Once Raspbian is installed, download and install arduPi library in a

new folder.

 Ex: “home/pi/ardupi”

 Once downloaded, the library needs to be compiled.

 Download Links:

 For Raspberry Pi

 For Raspberry Pi 2

 Installation Steps:

§ unzip raspberrypi2.zip

§ cd raspberrypi_2.

§ chmod +x compile_rpi

§ ./compile_rpi

§ cd ..

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Template Code

Arduino Code

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Steps to Enable UART port

 By default Raspberry Pi uses UART as serial console. If we

want it for Serial Communication, we need to change this

default configuration.

 Steps:

  1. Open a terminal on the Raspberry Pi, or connect to

Raspberry Pi through SSH.

  1. Make a backup of the /boot/cmdline.txt file.

$ sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt

  1. Open the file /boot/cmdline.txt:

$ sudo nano /boot/cmdline.txt

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Steps to Enable UART port,

SPI and I2C

  1. Reboot Raspberry Pi

$ sudo reboot

To enable SPI and I2C following these steps:

  1. Enter in Raspberry Pi configuration:

$ sudo raspi-config

  1. Open “8 Advanced Options”.
  2. Open “A6 SPI” and click “Yes” and “Ok” to all.
  3. Repeat step 2 and then open “A7 I2C” and click “Yes” and

“Ok” to all.

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Compile the Program

 Once the code is prepared using the arduPi_template.cpp

 It needs to be compiled in-order to execute it.

 First copy the arduPi_template.cpp as test.cpp

 Then compile the test.cpp file as:

$ g++ -lrt -lpthread test.cpp arduPi.o -o test

Note:

 The -lrt flag is necessary because the library uses the function clock_gettime

(time.h).

 The -lpthread option is needed because attachInterrupt() and detachInterrupt()

functions use threads.

Accessing GPIO

Demonstration #

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Code

Set GPIO in

Output Mode

Toggle GPIO

Every 0.5 second

Accessing Serial Port

Demonstration #

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

15 December 2016

Prof. Jignesh Patoliya (CHARUSAT)

Code

Initialize

Serial Port

Dial Phone

Number

Console Print