SlideShare a Scribd company logo
IoT on Raspberry Pi
John Staveley MVP
30/09/2021
https://uk.linkedin.com/in/johnstaveley/
@johnstaveley
About Me
 John Staveley MVP
 IT Contractor in C#, Mvc, Sql Server, Angular and Azure
 Organise LeedsSharp and IoTNorth etc
 Used microcontrollers, Not an electronics expert!
What we will cover
 Programming with C# on a Raspberry Pi
 Setup .Net 5
 Control the things
 GPIO, PWM, I2C
 Control from the outside world
 Azure IoTHub
Hardware Overview
 Raspberry Pi 4-b, Wifi, Camera
port
 GPIO, SPI, USB2/3, Ethernet,
HDMI etc
 MicroSD card and USB-C power
 Meadow
 .Net Nanoframework on ESP32
Prepare for launch
 USB-C Power supply (3A)
 Noobs on MicroSD card
 Screen (Micro-HDMI), Keyboard (USB 2/3), Mouse (USB 2/3)
 Wifi (fixed IP)
Basic Raspbian setup
 Install .Net 5 https://www.petecodes.co.uk/install-and-use-microsoft-dot-
net-5-with-the-raspberry-pi/
 Install VS Code
 Security settings
Control the things
 Digital Input/Output
 PWM
 I2C
 Camera
 Docs for C#: https://github.com/dotnet/iot
 using System.Device.Gpio
 using Iot.Device.Bindings
PIN Layout
Ref: https://pinout.xyz/pinout/5v_power#
Hello World
Digital Output Code
 Install-Package System.Device.IO
Digital output examples
 LED
 Buzzer
 Infrared LED
 Laser
 Relay
 Multi-LED
 … and lots more
Electronics
 Hardware recipes:
https://gpiozero.readthedocs.io/e
n/stable/recipes.html#led
 Pull up/down
 Anti-short
 Anti back EMF diodes
 Geekcreit 45 In 1 Sensor Module
Board Starter Kits Upgrade
Version For Arduino (Banggood
£15)
 https://images-eu.ssl-images-
amazon.com/images/I/C1lrpIfADa
S.pdf
Azure IoT Hub
 Free for < 8000 messages per month
 Control hundreds of devices
 Event Hubs
 HTTP, AQMP, MQTT
 Device Twins
 IoT Edge
 Setup:
 Create IoTHub in Azure portal
 Create device in portal
 Set up a direct method
DEMO
Controlling using Azure IoT
Explorer
Connecting device to Azure IoT Hub
 Get DEVICE connection string from IoTHub
DeviceClient _deviceClient =
DeviceClient.CreateFromConnectionString(configuration.IoTHubConnect
ionString);
await _deviceClient.SetMethodHandlerAsync(“MyMethod”, ActionMethod,
null);
….
private static async Task<MethodResponse>
ActionMethod(MethodRequest methodRequest, object userContext)
{
var data = methodRequest.DataAsJson;
var controlAction =
JsonConvert.DeserializeObject<ControlAction>(data);
Development experience
 Develop in Visual Studio
 Publish to directory
 Deployment: self-contained
 Target runtime: linux-arm
 Target framework: net5.0
 Fixed IP
 SFTP files using FileZilla
 VNC
 chown <user> <Directory or File> e.g. chown pi ./Control
 chmod +rwx <Directory> e.g. chmod +rwx ./Control
 ./<My dll name> e.g. ./Control
Digital input examples
 Push button
 Reed switch
 Magnetic sensor
 Tilt switch
 Ball switch
 Knock sensor
 Light blocking
 Infrared receiver
 Motion sensor
Pulse-width Modulation
(PWM)
Pulse-width Modulation
Examples
 Servos
 Lamps/LED
 Motors
 Pumps
 Fan
 Display Dial
 Audio effects https://www.youtube.com/watch?v=l4cuy1HOR3E
 …and lots more
Pulse-width Modulation Setup
PWM Code
 Software PWM
 Hardware PWM
var _servo1 = new SoftwarePwmChannel(18, 400, 0.9, true);
_servo1.Start();
_servo1.DutyCycle = 0;
_servo1.DutyCycle = 50;
_servo1.DutyCycle = 100;
I2C Overview
 Inter-Integrated Circuit (I2C)
 Two wire communication
 Pin 3, 5 and 27, 28
 Short range, multiple devices
 Enable on hardware
 sudo apt-get install i2c-tools
 sudo i2cdetect –y 1
I2C Examples
 Relay controller
 PWM controller
 Digital IO Expansion
 LCD screen
 Analogue inputs
 GPS
 RFID
 Rotary encoder (Volume switch)
 Temperature, Pressure, Humidity
 Accelerometer
 EEPROM
Aside:
Prototyping
 Jumper cables (M-F, F-F)
 Din rail mounting
 Connector blocks
 Breadboard
 Totemmaker
I2C Hardware – PWM controller
I2C PWM controller - code
Choosing hardware
 https://shop.pimoroni.com
 https://github.com/dotnet/iot/tree/
main/src/devices
 No driver? Translate the I2C interface!
I2C Relay Hat
 Solenoids
 High ampage lamps
 Fireworks
 …See code in project
I2C Relay hat - code
// Set relay 0 to 3, control Action 0 or 1
// Get relayNumber 0 to 3, returns either 0 or 1
… see code e.g. SetRelay
Connecting service to Azure IoT Hub
 Get SERVICE connection string
ServiceClient _serviceClient =
ServiceClient.CreateFromConnectionString(configuration.IoTHubConnec
tionString);
var deviceMethod = new CloudToDeviceMethod(“MyMethod”);
var payload = JsonSerializer.Serialize(controlAction);
deviceMethod.SetPayloadJson(payload);
var result = await
_serviceClient.InvokeDeviceMethodAsync(_deviceId, deviceMethod);
DEMO
Website controlling remote
device
Digital Input example
Digital Input code
int _inputPin = 22;
System.Device.Gpio.GpioController _controller = new();
_controller.OpenPin(_inputPin, PinMode.Input);
var inputResult = _controller.Read(_inputPin);
Console.Log(inputResult); // High or Low
Camera
 Normal, Hi-def, infra-red
Summary
 You have the power using C# to control lots of types of hardware: I/O, PWM,
I2C, Camera
 Not everything you can buy can be controlled – yet!
 Azure IoT Hub can be used to connect to and control your device from the
internet
Get started
resources
 Starter kit:
https://thepihut.com/products/r
aspberry-pi-starter-kit
 “How to” book:
https://shop.pimoroni.com/produ
cts/the-official-raspberry-pi-
beginners-guide-4th-ed-uk
 45 in 1 sensor pack:
https://www.banggood.com/Gee
kcreit-45-In-1-Sensor-Module-
Board-Starter-Kits-Upgrade-
Version-For-Arduino-UN0-R3-
MEGA2560-Plastic-Bag-Package-p-
1137050.html
Any Questions?
@johnstaveley
Demo code: https://github.com/johnstaveley/RaspberryPiControl
Slides: https://www.slideshare.net/johnstaveley/

More Related Content

What's hot

My presentation raspberry pi
My presentation raspberry piMy presentation raspberry pi
My presentation raspberry pi
HusainBhaldar21
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
praveen_23
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
Vijay Vishwakarma
 
Introduction to Raspberry PI
Introduction to Raspberry PIIntroduction to Raspberry PI
Introduction to Raspberry PI
Chandrashekar Babu
 
Raspberry pi
Raspberry piRaspberry pi
Raspberry pi
Pravesh Sahu
 
Building Blocks for IoT Devices
Building Blocks for IoT DevicesBuilding Blocks for IoT Devices
Building Blocks for IoT Devices
Anil Gorthy
 
Raspberry Pi Technology
Raspberry Pi TechnologyRaspberry Pi Technology
Raspberry Pi Technology
Ravi Basil
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
동호 손
 
Introduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiIntroduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry Pi
Ahmad Hafeezi
 
Raspberrypi best ppt
Raspberrypi best ppt Raspberrypi best ppt
Raspberrypi best ppt
SOMRAJ GAUTAM
 
IoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdfIoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdf
GVNSK Sravya
 
ESP32 IoT presentation @ dev.bg
ESP32 IoT presentation @ dev.bgESP32 IoT presentation @ dev.bg
ESP32 IoT presentation @ dev.bg
Martin Harizanov
 
Raspberry pi complete setup
Raspberry pi complete setupRaspberry pi complete setup
Raspberry pi complete setup
Santosh Kumar Kar
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using Python
Seggy Segaran
 
Raspberry pi ppt
Raspberry pi pptRaspberry pi ppt
Raspberry pi ppt
PavanKumar3601
 
Simple Presentation On Raspberry pi
Simple Presentation On Raspberry piSimple Presentation On Raspberry pi
Simple Presentation On Raspberry pi
Sakkar Chowdhury
 
Raspberry pi : an introduction
Raspberry pi : an introductionRaspberry pi : an introduction
Raspberry pi : an introduction
LTG Oxford
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
ABHIJITPATRA23
 
RaspberryPiPico.pptx
RaspberryPiPico.pptxRaspberryPiPico.pptx
RaspberryPiPico.pptx
SakshiGupta294972
 

What's hot (20)

My presentation raspberry pi
My presentation raspberry piMy presentation raspberry pi
My presentation raspberry pi
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
Introduction to Raspberry PI
Introduction to Raspberry PIIntroduction to Raspberry PI
Introduction to Raspberry PI
 
Raspberry pi
Raspberry piRaspberry pi
Raspberry pi
 
Building Blocks for IoT Devices
Building Blocks for IoT DevicesBuilding Blocks for IoT Devices
Building Blocks for IoT Devices
 
Raspberry Pi Technology
Raspberry Pi TechnologyRaspberry Pi Technology
Raspberry Pi Technology
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
 
Introduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiIntroduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry Pi
 
Raspberrypi best ppt
Raspberrypi best ppt Raspberrypi best ppt
Raspberrypi best ppt
 
Raspberry pi
Raspberry piRaspberry pi
Raspberry pi
 
IoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdfIoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdf
 
ESP32 IoT presentation @ dev.bg
ESP32 IoT presentation @ dev.bgESP32 IoT presentation @ dev.bg
ESP32 IoT presentation @ dev.bg
 
Raspberry pi complete setup
Raspberry pi complete setupRaspberry pi complete setup
Raspberry pi complete setup
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using Python
 
Raspberry pi ppt
Raspberry pi pptRaspberry pi ppt
Raspberry pi ppt
 
Simple Presentation On Raspberry pi
Simple Presentation On Raspberry piSimple Presentation On Raspberry pi
Simple Presentation On Raspberry pi
 
Raspberry pi : an introduction
Raspberry pi : an introductionRaspberry pi : an introduction
Raspberry pi : an introduction
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
 
RaspberryPiPico.pptx
RaspberryPiPico.pptxRaspberryPiPico.pptx
RaspberryPiPico.pptx
 

Similar to IoT on Raspberry Pi

IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2
John Staveley
 
Bare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in LinuxBare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in Linux
Alexander Vanwynsberghe
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
Amarjeetsingh Thakur
 
How To Electrocute Yourself using the Internet
How To Electrocute Yourself using the InternetHow To Electrocute Yourself using the Internet
How To Electrocute Yourself using the Internet
Alexander Roche
 
Generating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdeviceGenerating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdevice
Alon Fliess
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
Codemotion
 
IoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT DevkitIoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT Devkit
Vasily Ryzhonkov
 
IoT on azure
IoT on azureIoT on azure
IoT on azure
Joanna Lamch
 
Eclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for MicrocontrollersEclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for Microcontrollers
MicroEJ
 
Hack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGSHack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGS
DevFest DC
 
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Codemotion Tel Aviv
 
Flash and Hardware
Flash and HardwareFlash and Hardware
Flash and Hardware
Kevin Hoyt
 
Home automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technologyHome automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technology
ratthaslip ranokphanuwat
 
Microsoft's view of the Internet of Things (IoT) by Imran Shafqat
Microsoft's view of the Internet of Things (IoT) by Imran ShafqatMicrosoft's view of the Internet of Things (IoT) by Imran Shafqat
Microsoft's view of the Internet of Things (IoT) by Imran Shafqat
Allied Consultants
 
Internet of Things (IoT) reference architecture using Azure -MIC - Lahore
Internet of Things (IoT) reference architecture using Azure -MIC - LahoreInternet of Things (IoT) reference architecture using Azure -MIC - Lahore
Internet of Things (IoT) reference architecture using Azure -MIC - Lahore
Information Technology University
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-pi
Eclipse Kura
 
Android 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and NetworkAndroid 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and Network
Caio Pereira
 
Android Things in action
Android Things in actionAndroid Things in action
Android Things in action
Stefano Sanna
 
Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2
FIWARE
 
PowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUGPowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUG
Taylor Riggan
 

Similar to IoT on Raspberry Pi (20)

IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2
 
Bare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in LinuxBare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in Linux
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
 
How To Electrocute Yourself using the Internet
How To Electrocute Yourself using the InternetHow To Electrocute Yourself using the Internet
How To Electrocute Yourself using the Internet
 
Generating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdeviceGenerating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdevice
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
 
IoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT DevkitIoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT Devkit
 
IoT on azure
IoT on azureIoT on azure
IoT on azure
 
Eclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for MicrocontrollersEclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for Microcontrollers
 
Hack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGSHack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGS
 
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
 
Flash and Hardware
Flash and HardwareFlash and Hardware
Flash and Hardware
 
Home automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technologyHome automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technology
 
Microsoft's view of the Internet of Things (IoT) by Imran Shafqat
Microsoft's view of the Internet of Things (IoT) by Imran ShafqatMicrosoft's view of the Internet of Things (IoT) by Imran Shafqat
Microsoft's view of the Internet of Things (IoT) by Imran Shafqat
 
Internet of Things (IoT) reference architecture using Azure -MIC - Lahore
Internet of Things (IoT) reference architecture using Azure -MIC - LahoreInternet of Things (IoT) reference architecture using Azure -MIC - Lahore
Internet of Things (IoT) reference architecture using Azure -MIC - Lahore
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-pi
 
Android 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and NetworkAndroid 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and Network
 
Android Things in action
Android Things in actionAndroid Things in action
Android Things in action
 
Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2
 
PowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUGPowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUG
 

More from John Staveley

Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
John Staveley
 
Image and Audio Detection using Edge Impulse
Image and Audio Detection using Edge ImpulseImage and Audio Detection using Edge Impulse
Image and Audio Detection using Edge Impulse
John Staveley
 
Product and Customer Development
Product and Customer DevelopmentProduct and Customer Development
Product and Customer Development
John Staveley
 
Getting started with satellite IoT
Getting started with satellite IoTGetting started with satellite IoT
Getting started with satellite IoT
John Staveley
 
Birdwatching using a Raspberry pi, Azure IoT Hub and Cognitive services
Birdwatching using a Raspberry pi, Azure IoT Hub and Cognitive servicesBirdwatching using a Raspberry pi, Azure IoT Hub and Cognitive services
Birdwatching using a Raspberry pi, Azure IoT Hub and Cognitive services
John Staveley
 
DevSecOps - automating security
DevSecOps - automating securityDevSecOps - automating security
DevSecOps - automating security
John Staveley
 
Azure functions and container instances
Azure functions and container instancesAzure functions and container instances
Azure functions and container instances
John Staveley
 
Non nullable reference types in C#8
Non nullable reference types in C#8Non nullable reference types in C#8
Non nullable reference types in C#8
John Staveley
 
Graph databases and SQL Server 2017
Graph databases and SQL Server 2017Graph databases and SQL Server 2017
Graph databases and SQL Server 2017
John Staveley
 
Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions
Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure FunctionsMessaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions
Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions
John Staveley
 
Why you should use Type script and EcmaScript 6
Why you should use Type script and EcmaScript 6Why you should use Type script and EcmaScript 6
Why you should use Type script and EcmaScript 6
John Staveley
 
Updated Mvc Web security updated presentation
Updated Mvc Web security updated presentationUpdated Mvc Web security updated presentation
Updated Mvc Web security updated presentation
John Staveley
 
Web security leeds sharp dot netnotts
Web security leeds sharp dot netnottsWeb security leeds sharp dot netnotts
Web security leeds sharp dot netnotts
John Staveley
 
Design Patterns - LFM and POM
Design Patterns - LFM and POMDesign Patterns - LFM and POM
Design Patterns - LFM and POM
John Staveley
 
Web security presentation
Web security presentationWeb security presentation
Web security presentation
John Staveley
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
John Staveley
 

More from John Staveley (16)

Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Image and Audio Detection using Edge Impulse
Image and Audio Detection using Edge ImpulseImage and Audio Detection using Edge Impulse
Image and Audio Detection using Edge Impulse
 
Product and Customer Development
Product and Customer DevelopmentProduct and Customer Development
Product and Customer Development
 
Getting started with satellite IoT
Getting started with satellite IoTGetting started with satellite IoT
Getting started with satellite IoT
 
Birdwatching using a Raspberry pi, Azure IoT Hub and Cognitive services
Birdwatching using a Raspberry pi, Azure IoT Hub and Cognitive servicesBirdwatching using a Raspberry pi, Azure IoT Hub and Cognitive services
Birdwatching using a Raspberry pi, Azure IoT Hub and Cognitive services
 
DevSecOps - automating security
DevSecOps - automating securityDevSecOps - automating security
DevSecOps - automating security
 
Azure functions and container instances
Azure functions and container instancesAzure functions and container instances
Azure functions and container instances
 
Non nullable reference types in C#8
Non nullable reference types in C#8Non nullable reference types in C#8
Non nullable reference types in C#8
 
Graph databases and SQL Server 2017
Graph databases and SQL Server 2017Graph databases and SQL Server 2017
Graph databases and SQL Server 2017
 
Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions
Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure FunctionsMessaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions
Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions
 
Why you should use Type script and EcmaScript 6
Why you should use Type script and EcmaScript 6Why you should use Type script and EcmaScript 6
Why you should use Type script and EcmaScript 6
 
Updated Mvc Web security updated presentation
Updated Mvc Web security updated presentationUpdated Mvc Web security updated presentation
Updated Mvc Web security updated presentation
 
Web security leeds sharp dot netnotts
Web security leeds sharp dot netnottsWeb security leeds sharp dot netnotts
Web security leeds sharp dot netnotts
 
Design Patterns - LFM and POM
Design Patterns - LFM and POMDesign Patterns - LFM and POM
Design Patterns - LFM and POM
 
Web security presentation
Web security presentationWeb security presentation
Web security presentation
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
 

Recently uploaded

GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 

Recently uploaded (20)

GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 

IoT on Raspberry Pi

  • 1. IoT on Raspberry Pi John Staveley MVP 30/09/2021 https://uk.linkedin.com/in/johnstaveley/ @johnstaveley
  • 2. About Me  John Staveley MVP  IT Contractor in C#, Mvc, Sql Server, Angular and Azure  Organise LeedsSharp and IoTNorth etc  Used microcontrollers, Not an electronics expert!
  • 3. What we will cover  Programming with C# on a Raspberry Pi  Setup .Net 5  Control the things  GPIO, PWM, I2C  Control from the outside world  Azure IoTHub
  • 4. Hardware Overview  Raspberry Pi 4-b, Wifi, Camera port  GPIO, SPI, USB2/3, Ethernet, HDMI etc  MicroSD card and USB-C power  Meadow  .Net Nanoframework on ESP32
  • 5. Prepare for launch  USB-C Power supply (3A)  Noobs on MicroSD card  Screen (Micro-HDMI), Keyboard (USB 2/3), Mouse (USB 2/3)  Wifi (fixed IP)
  • 6. Basic Raspbian setup  Install .Net 5 https://www.petecodes.co.uk/install-and-use-microsoft-dot- net-5-with-the-raspberry-pi/  Install VS Code  Security settings
  • 7. Control the things  Digital Input/Output  PWM  I2C  Camera  Docs for C#: https://github.com/dotnet/iot  using System.Device.Gpio  using Iot.Device.Bindings
  • 10. Digital Output Code  Install-Package System.Device.IO
  • 11. Digital output examples  LED  Buzzer  Infrared LED  Laser  Relay  Multi-LED  … and lots more
  • 12. Electronics  Hardware recipes: https://gpiozero.readthedocs.io/e n/stable/recipes.html#led  Pull up/down  Anti-short  Anti back EMF diodes  Geekcreit 45 In 1 Sensor Module Board Starter Kits Upgrade Version For Arduino (Banggood £15)  https://images-eu.ssl-images- amazon.com/images/I/C1lrpIfADa S.pdf
  • 13. Azure IoT Hub  Free for < 8000 messages per month  Control hundreds of devices  Event Hubs  HTTP, AQMP, MQTT  Device Twins  IoT Edge  Setup:  Create IoTHub in Azure portal  Create device in portal  Set up a direct method
  • 15. Connecting device to Azure IoT Hub  Get DEVICE connection string from IoTHub DeviceClient _deviceClient = DeviceClient.CreateFromConnectionString(configuration.IoTHubConnect ionString); await _deviceClient.SetMethodHandlerAsync(“MyMethod”, ActionMethod, null); …. private static async Task<MethodResponse> ActionMethod(MethodRequest methodRequest, object userContext) { var data = methodRequest.DataAsJson; var controlAction = JsonConvert.DeserializeObject<ControlAction>(data);
  • 16. Development experience  Develop in Visual Studio  Publish to directory  Deployment: self-contained  Target runtime: linux-arm  Target framework: net5.0  Fixed IP  SFTP files using FileZilla  VNC  chown <user> <Directory or File> e.g. chown pi ./Control  chmod +rwx <Directory> e.g. chmod +rwx ./Control  ./<My dll name> e.g. ./Control
  • 17. Digital input examples  Push button  Reed switch  Magnetic sensor  Tilt switch  Ball switch  Knock sensor  Light blocking  Infrared receiver  Motion sensor
  • 19. Pulse-width Modulation Examples  Servos  Lamps/LED  Motors  Pumps  Fan  Display Dial  Audio effects https://www.youtube.com/watch?v=l4cuy1HOR3E  …and lots more
  • 21. PWM Code  Software PWM  Hardware PWM var _servo1 = new SoftwarePwmChannel(18, 400, 0.9, true); _servo1.Start(); _servo1.DutyCycle = 0; _servo1.DutyCycle = 50; _servo1.DutyCycle = 100;
  • 22. I2C Overview  Inter-Integrated Circuit (I2C)  Two wire communication  Pin 3, 5 and 27, 28  Short range, multiple devices  Enable on hardware  sudo apt-get install i2c-tools  sudo i2cdetect –y 1
  • 23. I2C Examples  Relay controller  PWM controller  Digital IO Expansion  LCD screen  Analogue inputs  GPS  RFID  Rotary encoder (Volume switch)  Temperature, Pressure, Humidity  Accelerometer  EEPROM
  • 24. Aside: Prototyping  Jumper cables (M-F, F-F)  Din rail mounting  Connector blocks  Breadboard  Totemmaker
  • 25. I2C Hardware – PWM controller
  • 27. Choosing hardware  https://shop.pimoroni.com  https://github.com/dotnet/iot/tree/ main/src/devices  No driver? Translate the I2C interface!
  • 28. I2C Relay Hat  Solenoids  High ampage lamps  Fireworks  …See code in project
  • 29. I2C Relay hat - code // Set relay 0 to 3, control Action 0 or 1 // Get relayNumber 0 to 3, returns either 0 or 1 … see code e.g. SetRelay
  • 30. Connecting service to Azure IoT Hub  Get SERVICE connection string ServiceClient _serviceClient = ServiceClient.CreateFromConnectionString(configuration.IoTHubConnec tionString); var deviceMethod = new CloudToDeviceMethod(“MyMethod”); var payload = JsonSerializer.Serialize(controlAction); deviceMethod.SetPayloadJson(payload); var result = await _serviceClient.InvokeDeviceMethodAsync(_deviceId, deviceMethod);
  • 33. Digital Input code int _inputPin = 22; System.Device.Gpio.GpioController _controller = new(); _controller.OpenPin(_inputPin, PinMode.Input); var inputResult = _controller.Read(_inputPin); Console.Log(inputResult); // High or Low
  • 35. Summary  You have the power using C# to control lots of types of hardware: I/O, PWM, I2C, Camera  Not everything you can buy can be controlled – yet!  Azure IoT Hub can be used to connect to and control your device from the internet
  • 36. Get started resources  Starter kit: https://thepihut.com/products/r aspberry-pi-starter-kit  “How to” book: https://shop.pimoroni.com/produ cts/the-official-raspberry-pi- beginners-guide-4th-ed-uk  45 in 1 sensor pack: https://www.banggood.com/Gee kcreit-45-In-1-Sensor-Module- Board-Starter-Kits-Upgrade- Version-For-Arduino-UN0-R3- MEGA2560-Plastic-Bag-Package-p- 1137050.html
  • 37. Any Questions? @johnstaveley Demo code: https://github.com/johnstaveley/RaspberryPiControl Slides: https://www.slideshare.net/johnstaveley/

Editor's Notes

  1. 3.5-5V and low ampage, use a relay to control greater power Do demo on board
  2. Deals with pull up/pull down, Back EMF diodes
  3. Emphasise this is not the only way of doing it DevOps is possible
  4. The main difference between a tilt switch and ball switch is speed, the mercury takes time to drop. Don’t use mercury in a child’s toy! A tilt ball switch can bounce if the movement is quick, use a latch in your software
  5. Enable Hardware PWM on raspberry pi 200 and 400 are Hertz values Do demo on device