AKBONE2020 用の P2パネル駆動にチャレンジ!

P2 の 128x64pixel 256x128mm のLEDパネルを20枚購入。


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/139524/326fff4b-a3ce-fda7-9eb6-cf6ca87ee394.png)

AVTOKYO 2022 で頒布するように用意したもの。 lovyan03 さんの協力を得て、LovyanGFX で動くようになったけれども、以下はそれまでにライブラリなしで直接動かすようにしてみたチャレンジの記録。

購入元はここ
https://item.taobao.com/item.htm?spm=a1z09.2.0.0.41bb2e8drPZmTc&id=575718731186&_u=21ieqpng729f
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/139524/3570b408-e94a-0f12-a9b4-323b5847111b.png)

なんだけど、前回のものとなにか違うぞ?

前回のもの(一番下)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/139524/81496041-ebc0-cbde-f37e-6b11740a1a51.png)

今回のは・・・あれ? D ピンと Eピン が無いぞ!?
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/139524/37f35a94-a2e0-7e6c-33a4-e9dc96074c06.png)


# 動かない

以前のパネルで動いていたファームを動かしてみましたが、全然画面が出ない!


# 中身を調べてみる

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/139524/90cb3797-816e-708d-b158-df6bdcdd4131.png)

ラッチが6126B
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/139524/6b978c96-549b-5093-6ca3-84d1bc66c16c.png)


行デコーダはRT5957かな?

RT5957 のデータシート http://raffar.com.tw/upload_file/2019071017305286848.pdf


おっと、行デコーダーはシフトレジスタだぞ

ピン配線をテスターで調べてみましたが・・・なんだかおかしいな?

HUB75 GND - RT5957のピン2(DIN)-ピン10(DOUT) - 8台のRT5957のカスケード接続
HUB75 A - RT5957のピン4(BK)
HUB75 B - RT5957のピン3(LCK)
HUB75 C - 未接続?

通常のLEDパネルは A,B,C,D,場合によりE の4ビットまたは5ビットで行アドレスを指定するのですが、どうやらこのパネルは全然違うようだ。

列表示は他のLEDパネルと変わらないことがわかったのだけれど・・・

# PxMatrix 

ESP32 用の LED パネルドライバに PxMatrix というのがあります。
https://github.com/2dom/PxMatrix


どうもこの、SHIFTREG_ABC という動作に該当するのではないかと。


https://community.pixelmatix.com/t/led-module-p2-128-64-1-32-driver/414/10
そこらへんのサポートの経緯はこれかな?


# 動いたかな?

列指定は通常のままで、行指定は以下のようにしてみました。

```

void rowselect( int rowaddress )
{
int a,b,c,d,e;
  digitalWrite( OEPIN, HIGH );

  digitalWrite( A0PIN, HIGH );
  digitalWrite( A1PIN, LOW ); // LCLK
  digitalWrite( A2PIN, (rowaddress >> 4 ) & 0x01 );
  usleep(2);
  usleep(2);
  digitalWrite( A0PIN, LOW );
  usleep(2);
  usleep(2);
  digitalWrite( LATPIN, HIGH );
  usleep(2);
  digitalWrite( LATPIN, LOW );
  usleep(2);
  digitalWrite( OEPIN, LOW );
  usleep(2);
}

```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/139524/0731b2a4-d5a3-31dd-69cd-1a3669d88edf.png)


# テストスケッチ

ちょっと不安定?

```

#include <stdio.h>
#include <string.h>

#define R1PIN     33
#define G1PIN     32
#define B1PIN     25
#define R2PIN     18
#define G2PIN     19
#define B2PIN     5
#define A0PIN     12
#define A1PIN     14
#define A2PIN     27
#define A3PIN     26
#define A4PIN       4 // GND
#define CLKPIN    4
#define LATPIN    17
#define OEPIN     16

#define LEDPANEL_X      128
#define LEDPANEL_Y      64




int  led_color;

const unsigned char  mask_pattern[8] = {
  0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};

const unsigned char  char_dat_yoko[ 1024 ] = {


//bank 0
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b10000001,0b01111100,0b00110000,0b00111100,0b01111100,0b00001000,0b11111110,0b01111100,0b11111110,0b01111100,0b01111100,0b00111000,0b11111100,0b01111100,0b11110000,0b11111110,
0b11000011,0b10000010,0b00010000,0b01000010,0b10000010,0b00010000,0b10000000,0b10000010,0b00000100,0b10000010,0b10000010,0b00101000,0b10000010,0b10000010,0b10001000,0b10000000,
0b11100111,0b10000010,0b00010000,0b10000010,0b00000010,0b00100000,0b10000000,0b10000000,0b00000000,0b10000010,0b10000010,0b01000100,0b10000010,0b10000000,0b10000100,0b10000000,
0b11111111,0b10000010,0b00010000,0b00000010,0b00001110,0b01000100,0b11111100,0b11111100,0b00001000,0b01111100,0b01111110,0b01000100,0b11111100,0b10000000,0b10000010,0b11111110,
0b01111110,0b10000010,0b00010000,0b00001100,0b00000010,0b11111110,0b00000010,0b10000010,0b00010000,0b10000010,0b00000100,0b01111010,0b10000010,0b10000000,0b10000010,0b10000000,
0b00011000,0b10000010,0b00010000,0b01000000,0b10000010,0b00000100,0b00000010,0b10000010,0b01000000,0b10000010,0b00001000,0b10000010,0b10000010,0b10000000,0b10000010,0b10000000,
0b00000000,0b01111100,0b00111000,0b11111110,0b01111100,0b00000100,0b01111100,0b01111100,0b10000000,0b01111100,0b00010000,0b10000010,0b11111100,0b01111100,0b11111110,0b11111110,

0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b01111100,0b00110000,0b00111100,0b01111100,0b00001000,0b11111110,0b01111100,0b11111110,0b01111100,0b01111100,0b00111000,0b11111100,0b01111100,0b11110000,0b11111110,0b11111110,
0b10000010,0b00010000,0b01000010,0b10000010,0b00010000,0b10000000,0b10000010,0b00000100,0b10000010,0b10000010,0b00101000,0b10000010,0b10000010,0b10001000,0b10000000,0b10000000,
0b10000010,0b00010000,0b10000010,0b00000010,0b00100000,0b10000000,0b10000000,0b00000000,0b10000010,0b10000010,0b01000100,0b10000010,0b10000000,0b10000100,0b10000000,0b10000000,
0b10000010,0b00010000,0b00000010,0b00001110,0b01000100,0b11111100,0b11111100,0b00001000,0b01111100,0b01111110,0b01000100,0b11111100,0b10000000,0b10000010,0b11111110,0b11111100,
0b10000010,0b00010000,0b00001100,0b00000010,0b11111110,0b00000010,0b10000010,0b00010000,0b10000010,0b00000100,0b01111010,0b10000010,0b10000000,0b10000010,0b10000000,0b10000000,
0b10000010,0b00010000,0b01000000,0b10000010,0b00000100,0b00000010,0b10000010,0b01000000,0b10000010,0b00001000,0b10000010,0b10000010,0b10000000,0b10000010,0b10000000,0b10000000,
0b01111100,0b00111000,0b11111110,0b01111100,0b00000100,0b01111100,0b01111100,0b10000000,0b01111100,0b00010000,0b10000010,0b11111100,0b01111100,0b11111110,0b11111110,0b10000000,

0b11111000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b11111100,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
  
0b11111110,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b11111111,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
// bank 1
0b10101010,0b10101010,0b00000001,0b00000011,0b00000111,0b00001111,0b00011111,0b00111111,0b01111111,0b11111111,0b00000000,0b00011111,0b00001111,0b00000111,0b00000011,0b00000001,
0b01111110,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00111100,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00011000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b10000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b01000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00100000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00010000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,

0b00001000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000100,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000010,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b10000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b01000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00100000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00010000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,

0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
  
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,

} ;


void rowselect( int rowaddress )
{
int a,b,c,d,e;
  digitalWrite( OEPIN, HIGH );

  digitalWrite( A0PIN, HIGH );
  digitalWrite( A1PIN, LOW ); // LCLK
  digitalWrite( A2PIN, (rowaddress >> 4 ) & 0x01 );
  usleep(2);
  usleep(2);
  digitalWrite( A0PIN, LOW );
  usleep(2);
  usleep(2);
  digitalWrite( LATPIN, HIGH );
  usleep(2);
  digitalWrite( LATPIN, LOW );
  usleep(2);
  digitalWrite( OEPIN, LOW );
  usleep(2);
}




void setup( void )
{

  Serial.begin(4800);

  pinMode( R1PIN,  OUTPUT );
  pinMode( G1PIN,  OUTPUT );
  pinMode( B1PIN,  OUTPUT );
  pinMode( R2PIN,  OUTPUT );
  pinMode( G2PIN,  OUTPUT );
  pinMode( B2PIN,  OUTPUT );
  pinMode( A0PIN,   OUTPUT );
  pinMode( A1PIN,   OUTPUT );
  pinMode( A2PIN,   OUTPUT );
  pinMode( A3PIN,   OUTPUT );
 // pinMode( A4PIN,   OUTPUT );
  pinMode( CLKPIN, OUTPUT );
  pinMode( LATPIN, OUTPUT );
  pinMode( OEPIN,  OUTPUT );
  digitalWrite( CLKPIN, LOW );
  digitalWrite( LATPIN, LOW );
  digitalWrite( OEPIN, LOW );

  led_color = 2;
}


void loop( void )
{
  int  dr, dg, db;
  int  row, col;
  int  rowaddress;
  unsigned char  *buff1;
  int test;
  dr = 0;
  dg = 0;
  db = 0;
  if( led_color & 0x1 ) dr = 1;
  if( led_color & 0x2 ) db = 1;
  if( led_color & 0x4 ) dg = 1;
  Serial.printf( "color DR=%d  DG=%d  DB=%d\n", dr, dg, db );

  buff1 = (unsigned char *)char_dat_yoko ;

  while( 1 ) {
    for( rowaddress=0 ; rowaddress<32; rowselect( rowaddress++ ) ) {

        for( col=0 ; col<LEDPANEL_X ; col++ ) {
          if( (buff1[ rowaddress*LEDPANEL_X/8 + (col >> 3) ] & mask_pattern[ col & 0x07 ]) != 0 ) {
            digitalWrite( R1PIN, dr );
            digitalWrite( G1PIN, dg );
            digitalWrite( B1PIN, db );
          } else {
            digitalWrite( R1PIN, LOW );
            digitalWrite( G1PIN, LOW );
            digitalWrite( B1PIN, LOW );
          }
          if( (buff1[ (LEDPANEL_X/8)*LEDPANEL_Y/2+rowaddress*LEDPANEL_X/8 + (col >> 3) ] & mask_pattern[ col & 0x07 ]) != 0 ) {
            digitalWrite( R2PIN, dr );
            digitalWrite( G2PIN, dg );
            digitalWrite( B2PIN, db );
          } else {
            digitalWrite( R2PIN, LOW );
            digitalWrite( G2PIN, LOW );
            digitalWrite( B2PIN, LOW );
          }
          digitalWrite( CLKPIN, HIGH );
          digitalWrite( CLKPIN, LOW );
        }

      
    }
  }
}
```