From e0a3ca6fe6dcca8b7557063a1d99ff614d9547fa Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Mon, 16 May 2022 23:16:20 +0000
Subject: [PATCH] Further development of firmware for Bluetooth data transmission.

---
 documentation/project_progress.tex |  146 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 139 insertions(+), 7 deletions(-)

diff --git a/documentation/project_progress.tex b/documentation/project_progress.tex
index b8825c7..15e43a9 100644
--- a/documentation/project_progress.tex
+++ b/documentation/project_progress.tex
@@ -1,10 +1,31 @@
 \documentclass[12pt]{article}
 \usepackage{graphicx}
-\begin{document}
-\section{Camera}
-\subsection{Model and make}
+\title{Development of trigger circuit for Intel Realsense D455}
+\author{Samo Peni\v{c}}
+\date{\today}
 
-Intel Realsense D455
+\begin{document}
+\maketitle
+\tableofcontents
+\section{Introduction}
+
+The scope of this document is a description of the development of the camera trigger circuit. The camera Intel Realsense D455 can output trigger signal and that signal needs to be level shifted in order to trigger the ADC in use for accelerometer/strain gauge measurements and it is mounted on the back side of the camera. The electrical specifications for the level shifter is as following:
+
+\begin{tabular}{l l l}
+	Parameter & Value & Comment \\ \hline
+	Input trigger voltage & 1.8 V & - \\
+	Output trigger voltage & 3.3 V & - \\
+	Power supply voltage & 3.3 V & - \\
+	Power consumption & $< 50$ mA & Estimated value \\
+	Wireless trigger frequency & 2.4 GHz & - \\
+	Wired Output trigger delay & - & Not yet measured\\
+	Wireless Output trigger delay & - & Not yet measured\\
+\end{tabular}
+
+
+
+\section{Camera}
+
 
 \subsection{Mechanical specifications}
 At the rear of the camera there are two M4 holes for mounting additional modules to the camera. The mechanical drawing is not that clear about the hole size, since there is also a mention of M3 at the same drawing. The part of the mechanical drawing regarding the back of the camera is presented in figure \ref{fig:rearmechanical}.
@@ -39,7 +60,7 @@
 \end{figure}
 
 
-The connector has pinout shown in the data table. According to the \cite{productFamilyDatasheet}, pins 5 and 9 shoud be used for synchronization. From the pinout, pin number 8 could be used to power up electronics. However, no data about electrical characteristics of power supply is given (max current?).
+The connector has pinout shown in the data table. According to the \cite{productFamilyDatasheet}, pins 5 and 9 shoud be used for synchronization. From the pinout, pin number 8 could be used to power up electronics. However, no data about electrical characteristics of power supply is given (max current?). \textbf{The cables in use, have a red wire at pin 1.}
  
 
 
@@ -67,6 +88,15 @@
 	\caption{ESP32 pinout.}\label{fig:esppinout}
 \end{figure}
 
+\subsection{Connection input and output trigger signals}
+
+Input trigger is connected to the GPIO17 pin. The input level of 1.8 V should be enough to trigger the event in the microcontroller, however, there are possibilities to include internal pullups or even add small electronics circuit to raise the voltage lever before it reaches the microcontroller.
+
+Output trigger is connected to the GPIO16 pin on the microcontroller. It has 3.3 V pulses, which are enough to trigger 5 V CMOS logic.
+
+\subsection{Connection of the power for microcontroller}
+
+The whole electronics is powered from the camera. The camera provides 3.3 V power supply at its connector. That power is routed to 3.3 V input on the microcontroller. The ground is shared with the signals and should be routed to one of the GND pins of the microcontroller. 
 
 \subsection{Connecting nRF24l01+}
 
@@ -108,14 +138,116 @@
 
 \section{Firmware}
 
+Firmware is written in Arduino. Arduino IDE has support for ESP32, however it needs to be installed from the inside of the IDE.
+
+Aditionally RF24 library is needed for communication with nRF24l01.
+
+
 \subsection{Energy conservation}
 
-WiFi.mode(WIFI\_OFF);
+Since no WiFi or BTLE communication from ESP32 is planned, it is suggested to turn off radion within Arduino IDE by issuing the following commands:
+
+\begin{verbatim}
+WiFi.mode(WIFI_OFF);
 btStop();
+\end{verbatim}
 
 \subsection{Input trigger and interrupt}
 
-https://lastminuteengineers.com/handling-esp32-gpio-interrupts-tutorial/
+Input trigger is routed into ESP32 module on pin GPIO17 and can be changed on any free pin. Output trigger is output to pin GPIO16 and can also be changed if necessary.
 
+The GPIO17 (shorter: pin 17) has an interrupt attached to it, so the processor responds on rising edge of the camera trigger signal as soon as possible. The attachemnt is done in setup part of the code.
+
+\begin{verbatim}
+ //pinMode(IN_TRIGGER, INPUT_PULLUP);
+  pinMode(OUT_TRIGGER, OUTPUT);
+  attachInterrupt(IN_TRIGGER, isr, RISING);
+\end{verbatim}
+
+Input internal pullup resistors are not enabled, but they shoud be if the trigger will behave erratically.
+
+The interrupt service routine is handling all the triggering on the output pin:
+
+\begin{verbatim}
+
+void IRAM_ATTR isr() {
+    digitalWrite(OUT_TRIGGER, HIGH);
+    delay(1);
+    digitalWrite(OUT_TRIGGER,LOW);
+}
+\end{verbatim}
+
+
+There is 1 ms pulse length on the output. It can be prolonged if necessary. Input trigger will possibly work on 1.8 V input voltage level. The output trigger has voltage level of 3.3 V and is well above the minimal 5 V CMOS voltage level specifications.
+
+%https://lastminuteengineers.com/handling-esp32-gpio-interrupts-tutorial/
+
+\subsection{nRF24l01 transmission code}
+
+The library RF24 that needs to be installed supports nRF21l01 communication. The nRF21l01 chip needs to be initialized by defining radio in the root of the code:
+
+\begin{verbatim}
+RF24 radio(22, 21); // CE, CSN
+
+const byte address[5] = {'R','E','C','V', '1'};
+char dataToSend[4] = "TRG";
+\end{verbatim}
+
+
+The radio will send a short, yet meaningful message (namely ``TRG'')to the receiver that will listen at the 5 byte address corresponding to the ascii letters of RECV1. The radio has pins 22 and 21 as CE and CSN connections.
+
+The second part of initalizations happens within the setup
+
+\begin{verbatim}
+  radio.begin();
+  radio.openWritingPipe(address);
+  radio.setPALevel(RF24_PA_MIN);
+\end{verbatim}
+
+It presets radio to low power transmission and defines the address of the receiver.
+
+In isr routine presented above, we just need to send a message by issuing:
+
+\begin{verbatim}
+radio.write( &dataToSend, sizeof(dataToSend) );
+\end{verbatim}
+
+\subsection{Debug receiver}
+
+To measure trigger delay and for other debugging purposes, A simple debug receiver can be programmed. On this receiver, the nRF21l01 must be connected the same way as on trasmitter. The following code works as debug interface. The code can also be a reference for receiver design.
+
+\begin{verbatim}
+#include <RF24_config.h>
+#include <nRF24L01.h>
+#include <RF24.h>
+#include <printf.h>
+
+RF24 radio(22, 21); // CE, CSN
+const byte address[6] = {'R','E','C','V', '1'};
+char val[4];
+
+void setup() {
+  Serial.begin(115200);
+  radio.begin();
+  radio.openReadingPipe(0, address);
+  radio.setPALevel(RF24_PA_MIN);
+  radio.startListening();
+
+}
+
+void loop() {
+  delay(5);
+  radio.startListening();
+  if ( radio.available()) {
+    while (radio.available()) {
+
+      radio.read(&val, sizeof(val));
+      Serial.print("Received = ");
+      Serial.println(val);
+    }
+  }
+
+}
+\end{verbatim}
 \end{document}
 

--
Gitblit v1.9.3