Multiple displays in network

Started by Jak

Jak

I have a project where I would like multiple displays in addition to sensors. The question is the best way to do this.
1 add a display to nocan
2 interface a pi zero to nocan
3 run a pi master as a slave

I’m not an arduino expert, but it looks like a mkrZero is not designed for a display. Am I correct? Any suggestions on options 2 or 3?

Thanks
-jak

Alain

Hi Jak,

There are tons of projects that connect an Arduino board to a display. This is usually done through SPI or I2C. The CANZERO being Arduino compatible can use the same techniques to connect to a display. I've been using a CANZERO to display information on a 16x2 character LCD. I wrote a sketch that makes the CANZERO display whatever is sent on a channel called "lcd", which is attached at the end of this post. For the wiring of an LCD to a CANZERO, you'll need a few jumper wires and you can take inspiration from the adafruit tutorials, but you'll need to adapt the pins to the CANZERO/Arduino MKR Zero.

If you want to connect graphical displays, it gets a little bit more complicated but not much more. Again, most of the stuff that exists out there for Arduino can be used for the CANZERO or Arduino MKR Zero.

Cheers,

Alain

 1#include <LiquidCrystal.h>
 2#include <nocan.h>
 3
 4// initialize the library with the numbers of the interface pins
 5LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
 6NocanChannelId cid;
 7
 8// Initialization
 9void setup() 
10{
11  lcd.begin(16, 2);              
12  lcd.print("OMZLO ONE SAYS:");  
13  lcd.setCursor(0, 1);
14  lcd.print("Initializing....");
15  
16  Nocan.open();
17
18  Nocan.registerChannel("lcd",&cid);
19  Nocan.subscribeChannel(cid);
20  
21  lcd.setCursor(0, 1);           // set the cursor to column 0, line 1
22  lcd.print("Waiting.........");
23}
24
25// main loop
26void loop() 
27{
28  int i;
29  NocanMessage msg;
30  int8_t status = Nocan.receiveMessage(&msg);
31  
32  if (status==0)
33  {
34      if (msg.data_len>16) msg.data_len=16;    
35      while (msg.data_len<16) msg.data[msg.data_len++]=' ';
36      msg.data[msg.data_len]=0;
37      
38      lcd.setCursor(0, 1);
39      lcd.print((const char *)msg.data);
40  }
41}

Jak

Alain,

It took me a while to get time and all the parts. I have successfully connected a CANZERO to an Adafruit RA8875 driver board (https://www.adafruit.com/product/1590) and a 7 inch TFT display (https://www.adafruit.com/product/2354).

I have included the Pin connections and a short sketch in case anyone else wants to try this. I should put the sketch in github somewhere, but have not.

Thanks for your advice.

-jak

//
// Demo sketch connecting a CANZERO to Adafruit RA8875 graphics driver board connected to a 7 inch 800x480 TFT display
//
// Warning, there is no error handling….
//
// jak.mang
// 02/17/19

#include #include #include

// Pin Out RA8875 -> CANZERO
// Vin: +5V
// GND: GND
// 3Vo: not connected (or use for the SPI fix circuit described in wiki)
// Lite: not connected
// SCK: SPI SCK
// MISO: SPI MISO (remember that it's not tristate! see SPI fix circuit if you want add some SPI device)
// MOSI: SPI MOSI
// CS: SPI CS Used Pin 7
// RST: Any MCU Pin or 10K resistor tied to 3V3 used Pin 6
// WAIT: Not used
// INT: Any MCU pin used Pin 2

#define RA8875_INT 2 //any pin
#define RA8875_CS 7 //any pin
#define RA8875_RST 6 //any pin

Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS,RA8875_RST);

void setup() {

NocanChannelId cid;

if (tft.begin(RA8875_800x480)) {
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);

  tft.fillScreen(RA8875_BLACK);
  tft.fillScreen(RA8875_WHITE);   }

Nocan.open();
Nocan.registerChannel("display", &cid);
Nocan.subscribeChannel(cid);
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

NocanMessage msg;

Nocan.receiveMessage(&msg);

if (msg.data[0] == 'o') {
// Turn on LED
digitalWrite(LED_BUILTIN, HIGH);
// Turn screen black
tft.fillScreen(RA8875_BLACK);
}
else if (msg.data[0] == 'x') {
// Turn off LED
digitalWrite(LED_BUILTIN, LOW);
// Turn screen white
tft.fillScreen(RA8875_WHITE);
}
}

Alain

Thanks jak, this is really nice.
I will share it on our blog if you don't mind.
Alain