Skip to content

Commit 3cb0e96

Browse files
author
AdamMiltonBarker
committedAug 3, 2020
Added ELEGOO UNO tutorials and updated EMAR Mini commands
1 parent 892e733 commit 3cb0e96

14 files changed

+607
-2
lines changed
 

‎Projects/RPI4/EMAR.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ def commands(self, topic, payload):
106106
cycle = 7.0
107107
servo = self.h1
108108
if(command["Type"]=="Arm"):
109-
if(command["Value"]=="RIGHT"):
109+
if(command["Value"]=="2UP"):
110110
cycle = 7.0
111111
servo = self.a1
112-
if(command["Value"]=="LEFT"):
112+
if(command["Value"]=="2DOWN"):
113113
cycle = 12.0
114114
servo = self.a1
115115
if(command["Value"] == "UP"):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Peter Moss COVID-19 AI Research Project
2+
## EMAR Mini Emergency Assistance Robot
3+
[![EMAR Emergency Assistance Robot](../../../Media/Images/EMAR-Mini.png)](https://github.com/COVID-19-Research-Project/EMAR-Mini)
4+
5+
 
6+
7+
# Table Of Contents
8+
9+
- [Introduction](#introduction)
10+
- [DISCLAIMER](#disclaimer)
11+
- [V1 Required Hardware](#v1-required-hardware)
12+
- [Prerequisites](#prerequisites)
13+
- [STLs For 3D Printing Tutorial](#stls-for-3d-printing-tutorial)
14+
- [Raspberry Pi 4 Tutorial](#raspberry-pi-4-tutorial)
15+
- [ELEGOO UNO R3 & Breadboard](#elegoo-uno-r3--breadboard)
16+
- [EMAR-RCR](#emar-rcr)
17+
- [EMAR-RCP](#emar-rcp)
18+
- [Installation](#installation)
19+
- [ESP8266 12F](#esp8266-12f)
20+
- [Continue](#continue)
21+
- [Contributing](#contributing)
22+
- [Contributors](#contributors)
23+
- [Versioning](#versioning)
24+
- [License](#license)
25+
- [Bugs/Issues](#bugs-issues)
26+
27+
 
28+
29+
# Introduction
30+
The following guide will take you through setting up and installing [EMAR Mini Emergency Assistance Robot](https://github.com/COVID-19-Research-Project/EMAR-Mini "EMAR Mini Emergency Assistance Robot").
31+
32+
The Raspberry Pi 4 homes the EMAR Mini software and powers the Intel hardware.
33+
34+
 
35+
36+
# DISCLAIMER
37+
38+
You should always be very careful when working with electronics! We will not accept responsibility for any damages done to hardware or yourself through full or partial use of this tutorial. Use this tutorial at your own risk, and take measures to ensure your own safety.
39+
40+
 
41+
42+
# V1 Required Hardware
43+
44+
- 1 x ELEGOO UNO R3 Remote Control
45+
- 1 x ELEGOO IR Receiver Module
46+
- 1 x Breadboard
47+
- 1 x ESP8266
48+
- 1 x USB to serial TTL UART Module
49+
- 2 x Push Buttons
50+
- 1 x 100Uf Ceramic Capacitor
51+
- 5 x 10k Resistors
52+
- 1 x Soldering Iron
53+
- Solder
54+
- Jumper wires
55+
56+
 
57+
58+
# Prerequisites
59+
60+
Before you can complete this tutorial there are some prerequisites.
61+
62+
## STLs For 3D Printing Tutorial
63+
64+
You need to have completed the [STLs For 3D Printing](../../STLs "STLs For 3D Printing") tutorial and printed the EMAR Mini parts.
65+
66+
## Raspberry Pi 4 Tutorial
67+
68+
You need to have completed the [Raspberry Pi 4](../../RPI4 "Raspberry Pi 4") tutorial and setup your EMAR Mini.
69+
70+
 
71+
72+
# Installation
73+
Now you will create your EMAR Mini Remote Control.
74+
75+
## ESP8266 12F
76+
![ESP8266 12F](../Media/Images/esp8266-12f.jpg)
77+
78+
First we will start with the ESP8266 12F. To start, heat up your soldering iron. Next you need to solder wires to the following pins:
79+
80+
- TXD0
81+
- RXD0
82+
- GPIO0
83+
- GPIO2
84+
- GPIO15
85+
- GND
86+
- VCC
87+
- RST
88+
- EN
89+
90+
In addition you need to solder the capacitor bridging between GND & VCC.
91+
92+
You are now ready to move on to setting up your ELEGOO UNO R3 and breadboard.
93+
94+
## ELEGOO UNO R3 & Breadboard
95+
![ELEGOO UNO R3 & Breadboard](../Media/Images/EMAR-Mini-Remote-Control_bb.png)
96+
97+
Follow the breadboard diagram above to set up your circuit. Here we are powering the ESP8266 directly from the 5V out of the ELEGOO UNO. As we are using the ESP8266, battery operation will not be possible as it will drain very quickly. You will need to plug your ELEGOO UNO into the mains using a suitable power adapter.
98+
99+
**WARNING: Many will advise not to power ESP8266 with 5V, however in my experience it is the only way that ESP8266 will work correctly with SSL. It is advised that the ESP8266 is not designed to run at 5V, however running at 3V you will more than likely not be able to make this project work. In all the years I have been using ESP8266, I have never had an issue with a single chip powering it with 5V. You should use 5V at your own discression**
100+
101+
The ESP8266 is used for WiFi communication, it connects to the iotJumpWay and waits for activity from the IR sensor, when it receives commands it sends via the iotJumpWay to EMAR Mini which allows you to control the robot using the remote control.
102+
103+
![ELEGOO UNO R3 & Breadboard](../Media/Images/EMAR-Mini-Remote-Control.jpg)
104+
105+
## iotJumpWay Credentials
106+
![iotJumpWay Credentials](../Media/Images/HIAS-iotJumpWay.png)
107+
Now we are going to set up the iotJumpWay Application. Head over to the HIAS UI and navigate to **IoT->Applications->Create**. Fill out the required information and click **Submit**. You will be taken to the newly created application page and will be able to access the application credentials.
108+
109+
## EMAR-RCP
110+
![EMAR-RCP](../Media/Images/EMAR-RCP.png)
111+
112+
EMAR-RCP is the publisher that sends the commands to EMAR Mini via the iotJumpWay.
113+
114+
To begin with you need to flash the [EMAR-RCP](../EMAR-RCP/EMAR-RCP.ino "EMAR-RCP") software to the ESP8266. You will need to make sure your Arduino enviornment is set up for [ESP8266 dev](https://arduino-esp8266.readthedocs.io/en/latest/installing.html) before you continue.
115+
116+
In the [EMAR-RCP](../EMAR-RCP/EMAR-RCP.ino "EMAR-RCP") file, you need to need to add your SSL certificate fingerprint, your WiFi details and iotJumpWay Application credentials.
117+
118+
To get your SSL certifcate fingerprint, you should click on the padlock in the browser window when you are on the HIAS UI
119+
120+
![Certificate](../Media/Images/certificate-1.png)
121+
Then click **Certificate**. This will open up a window with details about your certificate.
122+
123+
![Certificate](../Media/Images/certificate-2.png)
124+
Now click on **Details** and scroll down until you see **Thumbprint**. Click on Thumbprint and your certificate thumbprint will be displayed in the window. You should copy this thumbprint and paste it into the **fingerprint[]** setting at the top of the file (See below).
125+
126+
Now add your SSID and WiFi password to the settings, the URL of your HIAS server, and the iotJumpWay Application details. For the Zone and Device IDs you should use the Zone and Device ID of EMAR Mini.
127+
128+
```
129+
const char fingerprint[] PROGMEM = "";
130+
131+
const char* ssid = "";
132+
const char* password = "";
133+
134+
const char* mqtt_server = "";
135+
int mqttPort = 8883;
136+
137+
String locationID = "";
138+
String applicationID = "";
139+
char applicationName[] = "";
140+
char mqttUsername[] = "";
141+
char mqttPassword[] = "";
142+
char willTopic[50];
143+
144+
String zoneID = "";
145+
String deviceID = "";
146+
```
147+
Using your chosen USB to serial TTL UART Module and the breadboard, connect RX of the serial module to the TX of the ESP8266, next connect the TX of your serial module to the RX of ESP8266 and connect the power and ground cables (Make sure you move the UNO -> ESP8266 serial connection first).
148+
149+
Assuming you have the Arduino IDE set up, you can now flash the ESP8266. You will notice there are two push buttons. The one closest to the ESP8266 is for setting the ESP8266 into flash mode, the second button is for resetting the device.
150+
151+
Press the upload button in Arduino IDE and straight away hold the flashing button down, after a couple of seconds push the reset button and then release both. You should see the blue LED start to flash, this means that the ESP8266 is being flashed.
152+
153+
Once it has finished, the ESP8266 is ready.
154+
155+
## EMAR-RCR
156+
EMAR-RCR is the remote control receiver, it waits for commands sent from the remote control and sends them via serial to the RCP script running on the ESP8266.
157+
158+
![EMAR-RCR](../Media/Images/EMAR-RCR.png)
159+
160+
To begin with you need to flash the software to the ELEGOO UNO R3. Connect your UNO R3 to your computer.
161+
162+
Next you need to add the EMAR Mini Device ID to the settings at the top of the file.
163+
164+
```
165+
String deviceID = "";
166+
```
167+
168+
Once you flash the software to the ELEGOO UNO, you are now ready to continue.
169+
170+
# Continue
171+
172+
Now you can continue back to the [RPI4](../../RPI4 "RPI4") tutorial to complete setup.
173+
174+
 
175+
176+
# Contributing
177+
178+
The Peter Moss Acute COVID-19 AI Research project encourages and welcomes code contributions, bug fixes and enhancements from the Github.
179+
180+
Please read the [CONTRIBUTING](../../../CONTRIBUTING.md "CONTRIBUTING") document for a full guide to forking your repositories and submitting your pull requests. You will also find information about your code of conduct on this page.
181+
182+
## Contributors
183+
184+
- [Adam Milton-Barker](https://www.leukemiaresearchassociation.ai/team/adam-milton-barker "Adam Milton-Barker") - [Asociacion De Investigation En Inteligencia Artificial Para La Leucemia Peter Moss](https://www.leukemiaresearchassociation.ai "Asociacion De Investigation En Inteligencia Artificial Para La Leucemia Peter Moss") President & Lead Developer, Sabadell, Spain
185+
186+
 
187+
188+
# Versioning
189+
190+
You use SemVer for versioning. For the versions available, see [Releases](../../../releases "Releases").
191+
192+
 
193+
194+
# License
195+
196+
This project is licensed under the **MIT License** - see the [LICENSE](../../../LICENSE "LICENSE") file for details.
197+
198+
 
199+
200+
# Bugs/Issues
201+
202+
You use the [repo issues](../../../issues "repo issues") to track bugs and general requests related to using this project. See [CONTRIBUTING](../../../CONTRIBUTING.md "CONTRIBUTING") for more info on how to submit bugs, feature requests and proposals.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
Project: Peter Moss COVID-19 AI Research Project
3+
Repository: EMAR Mini, Emergency Assistance Robot
4+
5+
Author: Adam Milton-Barker (AdamMiltonBarker.com)
6+
Contributors:
7+
Title: EMAR Mini Remote Control iotJumpWay Publisher
8+
Description: The EMAR Mini Remote Control iotJumpWay Publisher
9+
receives IR commands from the Remote Control Receiver
10+
via serial and sends them to the iotJumpWay.
11+
License: MIT License
12+
Last Modified: 2020-07-04
13+
Credit: Based on example code from www.elegoo.com
14+
*/
15+
16+
#include <ArduinoJson.h>
17+
#include <ESP8266WiFi.h>
18+
#include <PubSubClient.h>
19+
#include <WiFiClientSecure.h>
20+
21+
static const char hias_cert[] PROGMEM = R"EOF(
22+
-----BEGIN CERTIFICATE-----
23+
-----END CERTIFICATE-----
24+
)EOF";
25+
26+
const char fingerprint[] PROGMEM = "";
27+
28+
const char* ssid = "";
29+
const char* password = "";
30+
31+
const char* mqtt_server = "";
32+
int mqttPort = 8883;
33+
34+
String locationID = "";
35+
String applicationID = "";
36+
char applicationName[] = "";
37+
char mqttUsername[] = "";
38+
char mqttPassword[] = "";
39+
char willTopic[50];
40+
41+
String zoneID = "";
42+
String deviceID = "";
43+
44+
BearSSL::WiFiClientSecure espClient;
45+
PubSubClient client(espClient);
46+
BearSSL::X509List cert(hias_cert);
47+
48+
char charBuf[50];
49+
50+
void setupWiFi() {
51+
52+
delay(10);
53+
54+
Serial.println();
55+
Serial.print("Connecting to WiFi network: ");
56+
Serial.println(ssid);
57+
58+
WiFi.mode(WIFI_STA);
59+
WiFi.begin(ssid, password);
60+
61+
while (WiFi.status() != WL_CONNECTED) {
62+
delay(500);
63+
Serial.print(".");
64+
}
65+
66+
Serial.println("");
67+
Serial.println("WiFi connected succesfully!");
68+
Serial.print("Device IP address: ");
69+
Serial.println(WiFi.localIP());
70+
71+
}
72+
73+
void callback(char* topic, byte* payload, unsigned int length) {
74+
75+
Serial.println("Unused");
76+
77+
}
78+
79+
void publishToApplicationStatus(const char* data){
80+
String statusTopic = locationID+"/Applications/"+applicationID+"/Status";
81+
statusTopic.toCharArray(charBuf, 50);
82+
client.publish(charBuf, data);
83+
}
84+
85+
void publishToDeviceCommands(const char* data){
86+
String commandTopic = locationID+"/Devices/"+zoneID+"/"+deviceID+"/Commands";
87+
commandTopic.toCharArray(charBuf, 50);
88+
client.publish(charBuf, data);
89+
}
90+
91+
void reconnect() {
92+
while (!client.connected()) {
93+
94+
Serial.println("Attempting connection to HIAS iotJumpWay Broker...");
95+
96+
String willTopicString = locationID+"/Applications/"+applicationID+"/Status";
97+
willTopicString.toCharArray(willTopic, 50);
98+
99+
if (client.connect(applicationName, mqttUsername, mqttPassword, willTopic, 0, 0, "OFFLINE")) {
100+
Serial.println("Connected to HIAS iotJumpWay Broker!");
101+
publishToApplicationStatus("ONLINE");
102+
} else {
103+
Serial.print("Failed to connect to HIAS iotJumpWay Broker, rc=");
104+
Serial.println(client.state());
105+
Serial.println("... trying again in 5 seconds");
106+
delay(5000);
107+
}
108+
109+
}
110+
}
111+
112+
void setup() {
113+
114+
Serial.begin(9600);
115+
116+
setupWiFi();
117+
//espClient.setTrustAnchors(&cert);
118+
espClient.setFingerprint(fingerprint);
119+
client.setServer(mqtt_server, mqttPort);
120+
client.setCallback(callback);
121+
}
122+
123+
void loop() {
124+
125+
if (!client.connected()) {
126+
reconnect();
127+
}
128+
client.loop();
129+
130+
while (Serial.available() > 0)
131+
{
132+
String jsReceived = Serial.readStringUntil('\n');
133+
134+
StaticJsonDocument<200> jsonBuffer;
135+
auto error = deserializeJson(jsonBuffer, jsReceived);
136+
if(error)
137+
{
138+
Serial.println("Command Not Sent");
139+
}
140+
else
141+
{
142+
char jsData[89];
143+
jsReceived.toCharArray(jsData, 89);
144+
publishToDeviceCommands(jsData);
145+
Serial.println("Command Sent");
146+
}
147+
}
148+
149+
delay(1000);
150+
}

0 commit comments

Comments
 (0)