Skip to content

SmartMDBController using Raspberry Pi and Arduino Mega

Notifications You must be signed in to change notification settings

RobKuipers/SmartMDBController

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project logo

Smart MDB Controller

Status


Smart MDB Controller

📝 Table of Contents

🧐 About

This repo contains circuit, firmware and backend for Smart MDB Controller Project.

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them.

- Raspberry Pi Model 3B, 3B+, 4B or CM4

Installation and Configuration

A step by step series that covers how to get the Firmware running.

Raspberry Pi Firmware Pre-Reqs

  1. Download and install the latest Raspberry Pi OS Desktop image to your SD card
  2. Open the terminal and execute the following command sudo raspi-config
  3. Then follow the following pictures to enable I2C bus on you raspberry pi
  • R1

  • R2

  • R3

  • R4

  • R5

  • Then do the same for Serial(UART)

  • R2

Configuring Raspberry Pi and Running the UI

  1. Copy FirmwareRPi folder to the desktop of your Raspberry Pi, open the terminal of your Raspberry Pi and execute the following commands
  - sudo apt-get update
  - sudo apt-get upgrade
  - sudo apt install python3-pip
  - pip3 install pyserial
  - pip3 install paho-mqtt
  - sudo adduser $USER dialout
  - cd ~/Desktop/FirmwareRPi
  - sudo chmod a+rx starter.sh
  1. To run the program just double click on starter.sh file
  2. or execute python3 /home/pi/Desktop/FirmwareRPi/Firmware.py

This program make use of MQTT to communicate with the webapp.

+ broker used is borker.hivemq.com
+ vending can be done by publishing an ammount to mdb/invoke topic

Arduino Mega Configurations

The following packages should be installed on your PC

  • AVR-GCC
  • AVRDUDE
  • avr-libc

Installing Pre-Reqs on Linux(Ubuntu or Debian Based Distro)

On Ubuntu or any Debian based Linux distro execute the following commands

  - sudo apt-get install -y gcc-avr
  - sudo apt-get install -y avrdude
  - sudo apt-get install avr-libc

Setup

  1. Open terminal in the atmega2560FW folder and execute make clean
  2. Open makefile, replace P=COM1 to the COM port of your arduino mega and save the file 1. Compile it with make all
  3. Upload it to your Arduino with make program

⛏️ Testing

  1. The Firmware can be tested on Raspberry Pi 3B, 3B+ or 4B with the following modifications
  2. Connect the sensor as shown in the Circuit Diagram section below.

🔌 Circuit Diagram

  • RPi 3,4 GPIOs Pinout

GPIOsRPi

  • Arduino Mega Pinout

GPIOsAMega

Circuit

GPIOsRPiCkt

Pins connections
Arduino Mega Logic Level Shifter
TX2 RX1
GND GND
HV 5V
RX2 TX0
Logic Level Shifter Raspberry Pi
RX0 UART0_TX
GND GND
LV 3.3V
TX1 UART0_RX
SN74HC14 Arduino Mega
2 RX1
3 TX1
4 & 5 Shorted
14 5V

Dashboard

You can use the dashboard with the link below:

https://nodered-proxy.production.wrapdrive.tech/ui/#!/0 dash

- The dashboard is running on a production server that is meant for testing only. 

-You should install and configure the dashboard on your Raspberry Pi or local server to keep it running.

Installing and Configuring Node-RED on Raspberry Pi

Conifguring NodeRED, MQTT is required only one time.

Open the terminal and execute the following commands

- sudo chmod a+rx starter.sh
- sudo apt install ufw
- sudo ufw enable
- sudo ufw allow tcp http https 1883 8883 1880
Installing MQTT(Mosquitto)

Open the terminal and execute the following commands

- sudo apt install -y mosquitto mosquitto-clients
- sudo systemctl enable mosquitto.service
- mosquitto -v
Installing and Configuring NodeRED

Open the terminal and execute the following commands

- bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
- sudo systemctl enable nodered.service
- npm install node-red-dashboard 
- sudo npm install node-red-dashboard
- sudo systemctl restart nodered.service

Then open NodeRED in your raspberry pi or using any other device which is connected to the same network as your Raspberry Pi is. In the browser you can type http://raspberrypi.local:1880 to open the node-red

  • Once node-red is opened, click on the menu button on the top left corner of the app and click on import.
  • Click on select file to import and select flows.json present in the dashboard directory of this repo.
  • After flows are imported, click on Deploy button on the top of the screen to save the changes.
  • You can access the Dashboard using http://raspberrypi.local:1880/ui

Components Used

  1. Raspberry Pi
  2. Logic Level Converter
  3. SN74HC14 Hex Inverter
  4. PC817 Optocoupler
  5. Arduino Mega
  6. 330 Ohm Resistor
  7. 1N4007 Diode

Datasheets

  • Optocoupler OHPC 817C F919G
  • Schimitt Trigger Hex Inverter PHILIPS 74HC14N B9784PS Hnn9840 E
  • Diode 1N4007 MIC AXIAL SILASTIC GUARD JUNCTION STANDARD RECTIFIER

⛏️ Built Using

  • Python3 - Raspberry Pi FW
  • Node-RED - Platform for creating dashbaords and backend logic

✍️ Authors

About

SmartMDBController using Raspberry Pi and Arduino Mega

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 74.5%
  • Makefile 22.3%
  • Python 3.1%
  • Shell 0.1%