Samo Penic
2022-03-28 d6fc89518a6a3a21d53823d83d2a8cf64957d678
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
\documentclass[12pt]{article}
\usepackage{graphicx}
\title{Development of trigger circuit for Intel Realsense D455}
\author{Samo Peni\v{c}}
\date{\today}
 
\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}.
 
\begin{figure}[bth]
    \begin{center}
\includegraphics[angle=-90, origin=c, width=0.6\linewidth]{figures/REARmechanical.png}
    \end{center}
    \caption{Rear of the Intel RealSense Depth Camera D455. All units in millimeters. Taken from \cite{productFamilyDatasheet}.}\label{fig:rearmechanical}
\end{figure}
 
The case was drawn with open source 3d cad software FreeCAD version 0.19. The size of the case is approx 2 mm larger as camera back side in both dimensions and is 12 mm thick, allowing enough space for mounting the ESP32 board and nRF24l01 module. The holes for synchronization cables from camera and output sinchronization are of diameter 3 mm. They are positioned in such a way, that they do not pose any mechanical problems for assembly. Improvement would be to put connectors to the case. Which ones?
 
\begin{figure}
    \begin{center}
        \includegraphics[width=0.6\linewidth]{figures/case_drawing.png}
    \end{center}
    \caption{Drawing of the case done in FreeCAD 0.19.}
\end{figure}
 
 
\subsection{Extension connector pinout}
 
For multicamera synchronization, the external senzor connector is placed at the top side wall of the camera. The 9 pin JST connector with manufacturer part number SM09B-SRSS TB(LF)(SN) with 1 mm pitch is used and is show in figure \ref{fig:connector}.
 
 
\begin{figure}[htb]
    \begin{center}
        \includegraphics[width=0.4\linewidth]{figures/connector.png}
    \end{center}
    \caption{Connector for sync signal. Taken from \cite{productFamilyDatasheet}. }\label{fig:connector}
\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?). \textbf{The cables in use, have a red wire at pin 1.}
 
 
 
\begin{figure}[htb]
    \begin{center}
        \includegraphics[width=0.7\linewidth]{figures/pinout.png}
    \end{center}
    \caption{Connector pinout. Taken from \cite{productFamilyDatasheet}.}\label{fig:pinout}
\end{figure}
 
 
For multi-camera case, one camera could be initialized as master and the rest configured as slave. Alternatively an external signal generator can also be used as the master trigger with all cameras set to slave mode. When applying an external sync pulse, the HW SYNC input requires a 100 microsecond positive pulse at the nominal camera frame rate, 33.33 ms for a 30Hz frame rate for example. Inputs are high impedance, 1.8V CMOS voltage levels.
 
However, it is important to make sure to use a high resolution signal generator. The frequency of the signal generator needs to exactly match the sensor frame rate. For example, if the sensor is set up as 30 fps, the real frame rate may be 30.015 fps. You may need to use an oscilloscope to measure the real frame and configure the signal generator to the same frequency.
 
For this reason, it may be better to just use one additional camera as master sync signal generator. \cite{whitesheet}
 
\section{ESP32 controller}
 
 
\begin{figure}[htb]
    \begin{center}
        \includegraphics[width=\linewidth]{figures/esppinout.png}
    \end{center}
    \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+}
 
For fast communication Nordic Semiconductor chip nRF24l01+ is used. It operates on 2.4 GHz frequency band, supports multiple channels, raw communication with possibilities of ACK/NoACK. The delay of wirelessly transporting the trigger should be minimal with pair of nRF24 where one is designated as transmitter and one as receiver. There is possibility of full duplex communication. No protocol is defined yet, so we have multiple possibilities on implementation.
 
As an advenced feature of the receiving end, there is a posibility to measure round trip of data transfer, therefore, the receiver can calculate the delay caused by the transmission and compensate for it, if the receiver does not need to trigger the event. As an example, this could be implemented when accelerometer is read and should be synchronized with camera frame capture. The receiver can measure acceleration beforehand in short intervals and put it into cyclic buffer. When the trigger is received and knowing the trigger transmission delay and accelerometer reading frequency, we can look up the value for acceleration at the exact time the camera published the event at the transmitter side. With this, we have possibility to minimize trigger delay.
 
nRF24l01 modules are used, where everyting regarding radio is implemented. Module has SPI and power supply pins on its connector. Image of module with its pinout is presented in figure \ref{fig:nrfpinout}.
 
\begin{figure}[htb]
    \begin{center}
        \begin{minipage}{0.45\linewidth}
        \includegraphics[width=0.9\linewidth]{figures/nrf_pinout.png}
        \end{minipage}
        \begin{minipage}{0.45\linewidth}
        \includegraphics[width=0.9\linewidth]{figures/nrf_electrical.png}
 
        \end{minipage}
    \end{center}
    \caption{nRF24l01 module pinout and its electrical characteristics. \cite{nrfInterfacing}}\label{fig:nrfpinout}
\end{figure}
 
 
 
Connection to ESP32 module is as presented in the following table:
 
\begin{tabular}{l | l | l}
nRF pin & ESP32 pin & comment \\ \hline
    1 & GND & Power and signal ground \\
    2 & 3.3V & Power supply \\
    3 & 22 & CE (Chip enable) \\
    4 & 21 & CSN \\
    5 & 18 & SCK \\
    6 & 23 & MOSI \\
    7 & 19 & MISO \\ \hline
\end{tabular}
 
 
 
\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}
 
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}
 
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}