11. Networking and Communications
Overview of week 11 assignment
- Group assignment
- send a message between two projects
- Individual assignment
- design, build, and connect wired or wireless node(s) with network or bus addresses and local input &/or output device(s)
1. Group assignment
For more information, see the Week 11: Group assignment page.
2. Individual assignment
A. I2C vs. CAN
I am interested in CAN protocol (controller area network bus) since I work in the construction machinery industry. In the class, I learned the basics of I2C, so decided to compare the two communication standards.
- Both I²C and CAN both use two wires to communicate and can connect multiple devices on the same bus. Each device or message has an identifier to keep things organized. They send data one bit at a time (serial communication).
- I²C (or I2C, IIC) uses single-ended signaling (relative to ground), making it more vulnerable to noise — any voltage spike can be misinterpreted as data.
- CAN, on the other hand, uses differential signaling (CAN_H - CAN_L), which cancels out noise that affects both wires equally. This makes CAN highly reliable in electrically noisy environments like vehicles or industrial systems.
Feature | I²C | CAN |
---|---|---|
Shared Bus | Yes (SDA + SCL) | Yes (CAN_H + CAN_L) |
Multi-Device Support | Yes (master-slave) | Yes (multi-master) |
Message Identification | 7/10-bit device address | 11/29-bit message ID |
Serial Communication | Yes | Yes |
Low Power | Yes | Yes |
Signal Type | Single-ended (vs. GND) | Differential (CAN_H - CAN_L) |
Typical Speed | 100 kbps – 3.4 Mbps | 125 kbps – 1 Mbps (CAN FD: up to 8 Mbps) |
Max Cable Length | ~1–10 m depending on speed | ~40–500 m depending on speed |
Error Handling | Basic ACK/NACK | CRC, ACK, retransmit, error counters |
Arbitration | Master-slave | Priority-based arbitration |
Termination Required | No | Yes (120Ω at both ends) |
Noise Immunity | Low | Very High |
Typical Use Case | On-board sensors, EEPROMs, displays | Automotives, robotics, industrial systems |
Ref.
B. OLED display using I2C
I tried using Monochrome 1.3" 128x64 SH1106G SPI OLED Monochrome Display, which uses I2C communication.
a. Specification
Specification | 1.3" 128x64 OLED |
---|---|
Display size | 1.3" (34.5 x 35.0mm) |
Communication protocol | I2C |
Voltage | 3.3V-5V |
Driver | SH1106 |
Number of pixels | 128 x 64 |
Pixel Pitch | 0.23 × 0.23(mm) |
Pixel Size | 0.21 × 0.21(mm) |
The I2C address can be determined by checking the notes on the back. The I2C address will be different depending on whether 0x7A
or 0x78
is connected. In this case, it says 0x78
so I2C address is 0x3C
.
Connection | 0x7A | 0x78 |
---|---|---|
I2C adress | 0x3A | 0x3C |
b. Wiring
OLED pins | RP2040 |
---|---|
GND | GND |
VCC | 5V |
SCL | SCL (GP7) |
SDA | SDA (GP6) |
c. Programing
I first used a sample program provided by Adafruit.
File > Examples > Adafruit SH110X > OLED_QTPY_SH1106 > SH1106_128x64_i2c_QTPY
I checked that the I2C address #define SCREEN_ADDRESS 0x3C
Arduino code
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
d. Test
Check components carefully!
At first, I mistakenly thought this display was an SSD1306, not SH1106 and uploaded the code. As a result, only a few rows of pixels near the top of the screen worked properly. The other rows display noise.
Ref.: I tried using a small OLED display SH1106 (1.3 inch) with Raspberry Pi Pico (Japanese)
- Pixel number refers to how many pixels are actually shown on the screen, whereas Memory size refers to how much display RAM the controller has.
- SH1106 has 132×64 memory, but only 128×64 are visible.
- SSD1306 starts writing at column 0, but SH1106's visible area starts at column 2. This causes horizontal misalignment — text shifts or cuts off.
- The SSD1306 library doesn’t account for the extra 4 columns, so data may overflow into hidden or unused memory. As more lines are drawn, the mismatch causes incorrect page addressing, leading to garbled or noisy lower rows. As a result, top few lines may partially align, but the rest become distorted.
Worked!
e. Customization
I then implemented a custom UI on the OLED display with animation, to better understand the program.
- Text Animation: The text moves from right to left across the screen.
- Rectangle Animation: Two rectangles move from left to right at different speeds.
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 |
|
C. CAN
I wanted to try using the CAN standard for in-vehicle electronics components, and it seems like I can do it with a microcontroller such as the XIAO RP2040, using a CAN controller and receiver like the one below.
- In-vehicle electronic components (switches, levers etc.)
- MCP2515 CAN Controller + TJA1050 CAN Transceiver
- Termination resistors (120Ω)
- CAN wiring (twisted pair: CAN_H and CAN_L)
- Power supply (3.3V or 5V)
I ran out of time so far.
3. Files
No files this week, code in the text.
Afterthoughts
- CAN can communicate more reliably than I2C.
- Worth exploring effective UI for tiny displays (Rabbit hole alert!)