stm32g031j6m6 ardunno側のプログラム あいてんどうの128x64のoled 文字16x16 #include <Arduino.h> #include <U8x8lib.h> #ifdef U8X8_HAVE_HW_SPI #include <SPI.h> #endif U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ PA8, /* data=*/ PA12, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display #define in7 PB7 void setup(void) { u8x8.begin(); pinMode(in7,INPUT_PULLUP); } char s[2] = {'@',0}; int ii,jj; int a; int b; int c; int d; int e; //5bit int f; //6bit int g; //7bit int tl_f; int tls; int tl; int cursor1; void loop(void) { u8x8.setFont(u8x8_font_px437wyse700b_2x2_r); char ss1[]="Hello"; ii=0; while(ss1[ii]!=0){ s[0]=ss1[ii]; // x y u8x8.drawString(ii*2,0,s); ii++; } delay(500); s[0]=' '; for(jj=0;jj<4;jj++){ for(ii=0;ii<8;ii++){ // x y u8x8.drawString(ii*2,jj*2,s); }//end for }//enf for //delay(200); u8x8.drawString(0, 0, "@"); //delay(200); //u8x8.refreshDisplay(); // only required for SSD1606/7 tl = 33; //シリアル 1ビットの長さ cursor1 = 0; while(1) { tl_f = 0;tls=33; while( digitalRead(in7) == 1 ) {} for(int loop_i=1;loop_i <= 33;loop_i++){ delay(1);if(digitalRead(in7) == 1 && tl_f == 0){tl_f=1;tls=loop_i*2;} } if(tl_f == 1) {tl = tls - 1;} // スタートビット目の次が1の場合と調整 a=!(digitalRead(in7)); delay(tl); b=!(digitalRead(in7)); delay(tl); c=!(digitalRead(in7)); delay(tl); d=!(digitalRead(in7)); delay(tl); e=!(digitalRead(in7)); // 5 bit delay(tl); f=!(digitalRead(in7)); // 6 bit delay(tl); g=!(digitalRead(in7)); // 7 bit delay(tl); s[0]=g*64+f*32+e*16+d*8+c*4+b*2+a; //s[0]='@'; //debug if( s[0]=='_' ) { //画面クリア s[0]=' '; for(jj=0;jj<4;jj++){ for(ii=0;ii<8;ii++){ // x y u8x8.drawString(ii*2,jj*2,s); }//end for }//enf for //カーソルのクリア cursor1 = 0; } else { //文字の表示 u8x8.drawString( ((cursor1-0) & 0x07 )*2, // x (cursor1>>3)*2, // y s); cursor1++; } if(cursor1 >= 32) { //画面クリア s[0]=' '; for(jj=0;jj<4;jj++){ for(ii=0;ii<8;ii++){ // x y u8x8.drawString(ii*2,jj*2,s); }//end for }//enf for //カーソルのクリア cursor1 = 0; } //endif //debug delay(200); } //while } //loop stm32f303k8 mbed側のプログラム あいてんどうの128x64のoled 文字8x16 #include "mbed.h" #include "SSD1306.h" #include "font_8x8.h" DigitalOut myled(LED1); DigitalIn myin9(PF_1); // for out 11 (in4) (303 D8) #define ADDR (0x3c<<1) // address //#define ADDR (0x3d<<1) // address I2C i2c(I2C_SDA, I2C_SCL); // Host PC Communication channels Serial pc(USBTX, USBRX); // tx, rx // Instantiate OLED SSD1306 oled(i2c, ADDR); char ddff[8*8]; void char11(int row,int com,int cha) { int char_index1; char_index1 = cha-0x20; int ii; for (ii = 0;ii<(8*2);ii++) {ddff[ii]=0;} // オールクリア for (ii =0;ii<8;ii++){ ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 0) & 1)<<0; //1bit 1 ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 0) & 1)<<1; //1bit 2 ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 1) & 1)<<2; //2bit 3 ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 1) & 1)<<3; //2bit 4 ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 2) & 1)<<4; //3bit 5 ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 2) & 1)<<5; //3bit 6 ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 3) & 1)<<6; //4bit 7 ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 3) & 1)<<7; //4bit 8 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 4) & 1)<<0; //5bit 1 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 4) & 1)<<1; //5bit 2 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 5) & 1)<<2; //6bit 3 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 5) & 1)<<3; //6bit 4 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 6) & 1)<<4; //7bit 5 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 6) & 1)<<5; //7bit 6 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 7) & 1)<<6; //8bit 7 ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 7) & 1)<<7; //8bit 8 }//for oled.writeBitmap((uint8_t*) ddff, row, (row + 2 - 1), //y com, (com + 8 - 1)); //x } //end chr11 int main() { int a; int b; int c; int d; int e; //5bit int f; //6bit int g; //7bit char s[2] = {'@',0}; int tl_f; int tls; int tl; int cursor1; int ii,jj; pc.baud(9600); myin9.mode( PullUp ); // 内蔵プルアップを使う // oled.writeString(0, 0, 13, "Hello World !"); //oled.writeString(0, 0, "Hello World !"); //char11(0,0,'H');char11(0,8,'e');char11(0,16,'l');char11(0,24,'l');char11(0,32,'o'); char ss1[]="Hello World !"; ii=0; while(ss1[ii]!=0){ char11(0,ii*8,ss1[ii]);ii++; } pc.printf("Printed something\r"); wait(3); // 1234567890123456 //oled.writeString(0, 0, "@ "); for(ii=0;ii<16;ii++){ char11(0,ii*8,' '); }//end for char11(0,0,'@'); e=0;f=0;g=0; tl = 33; //シリアル 1ビットの長さ cursor1 = 0; while(1) { tl_f = 0;tls=33; while( myin9 == 1 ) {} for(int loop_i=1;loop_i <= 33;loop_i++){ wait_ms(1);if(myin9 == 1 && tl_f == 0){tl_f=1;tls=loop_i*2;} } if(tl_f == 1) {tl = tls - 1;} // スタートビット目の次が1の場合と調整 //wait_ms(tl); //debug a=!(myin9); // 1bit wait_ms(tl); b=!(myin9); // 2bit wait_ms(tl); c=!(myin9); // 3bit wait_ms(tl); d=!(myin9); // 4bit 16 wait_ms(tl); e=!(myin9); // 5bit 32 wait_ms(tl); f=!(myin9); // 6bit 64 wait_ms(tl); g=!(myin9); // 6bit 64 wait_ms(tl); //a=0; // debug s[0]=g*64+f*32+e*16+d*8+c*4+b*2+a; if( s[0]=='_' ) { //画面クリア // 1234567890123456 //oled.writeString(0, 0, " "); for(jj=0;jj<4;jj++){ for(ii=0;ii<16;ii++){ char11(jj*2,ii*8,' '); }//end for }//enf for //カーソルのクリア cursor1 = 0; } else { //文字の表示 pc.printf(s); // y x //oled.writeString(0, cursor1, s); char11( (cursor1>>4)*2, ((cursor1-0) & 0x0f )*8, s[0]); cursor1++; //debug //s[0]='0'+(tl/10);oled.writeString(1, 0, s); //s[0]='0'+(tl%10);oled.writeString(1, 1, s); //debug //s[0]='0'+g;oled.writeString(2, 0, s); //s[0]='0'+f;oled.writeString(2, 1, s); //s[0]='0'+e;oled.writeString(2, 2, s); //s[0]='0'+d;oled.writeString(2, 3, s); //s[0]='0'+c;oled.writeString(2, 4, s); //s[0]='0'+b;oled.writeString(2, 5, s); //s[0]='0'+a;oled.writeString(2, 6, s); } if(cursor1 >= 32*2) { //画面クリア // 1234567890123456 //oled.writeString(0, 0, " "); for(jj=0;jj<4;jj++){ for(ii=0;ii<16;ii++){ char11(jj*2,ii*8,' '); }//end for }//end for //カーソルのクリア cursor1 = 0; } //endif //myled = 1; // LED is ON //wait(0.2); // 200 ms //myled = 0; // LED is OFF //wait(0.2); // 1 sec //oled.writeString(0, 0, "Hello World !"); //pc.printf("Printed something\r"); //wait(0.5); //debug } } stm32f303k8 mbed側のプログラム あいてんどうの128x64のoled #include "mbed.h" #include "SSD1306.h" DigitalOut myled(LED1); DigitalIn myin9(PF_1); // for out 11 (in4) (303 D8) #define ADDR (0x3c<<1) // address //#define ADDR (0x3d<<1) // address I2C i2c(I2C_SDA, I2C_SCL); // Host PC Communication channels Serial pc(USBTX, USBRX); // tx, rx // Instantiate OLED SSD1306 oled(i2c, ADDR); int main() { int a; int b; int c; int d; int e; //5bit int f; //6bit int g; //7bit char s[2] = {'@',0}; int tl_f; int tls; int tl; int cursor1; pc.baud(9600); myin9.mode( PullUp ); // 内蔵プルアップを使う // oled.writeString(0, 0, 13, "Hello World !"); oled.writeString(0, 0, "Hello World !"); pc.printf("Printed something\r"); wait(3); // 1234567890123456 oled.writeString(0, 0, "@ "); e=0;f=0;g=0; tl = 33; //シリアル 1ビットの長さ cursor1 = 0; while(1) { tl_f = 0;tls=33; while( myin9 == 1 ) {} for(int loop_i=1;loop_i <= 33;loop_i++){ wait_ms(1);if(myin9 == 1 && tl_f == 0){tl_f=1;tls=loop_i*2;} } if(tl_f == 1) {tl = tls - 1;} // スタートビット目の次が1の場合と調整 //wait_ms(tl); //debug a=!(myin9); // 1bit wait_ms(tl); b=!(myin9); // 2bit wait_ms(tl); c=!(myin9); // 3bit wait_ms(tl); d=!(myin9); // 4bit 16 wait_ms(tl); e=!(myin9); // 5bit 32 wait_ms(tl); f=!(myin9); // 6bit 64 wait_ms(tl); g=!(myin9); // 6bit 64 wait_ms(tl); //a=0; // debug s[0]=g*64+f*32+e*16+d*8+c*4+b*2+a; if( s[0]=='_' ) { //画面クリア // 1234567890123456 oled.writeString(0, 0, " "); //カーソルのクリア cursor1 = 0; } else { //文字の表示 pc.printf(s); // y x oled.writeString(0, cursor1, s); cursor1++; //debug //s[0]='0'+(tl/10);oled.writeString(1, 0, s); //s[0]='0'+(tl%10);oled.writeString(1, 1, s); //debug //s[0]='0'+g;oled.writeString(2, 0, s); //s[0]='0'+f;oled.writeString(2, 1, s); //s[0]='0'+e;oled.writeString(2, 2, s); //s[0]='0'+d;oled.writeString(2, 3, s); //s[0]='0'+c;oled.writeString(2, 4, s); //s[0]='0'+b;oled.writeString(2, 5, s); //s[0]='0'+a;oled.writeString(2, 6, s); } if(cursor1 >= 16) { //画面クリア // 1234567890123456 oled.writeString(0, 0, " "); //カーソルのクリア cursor1 = 0; } //endif //myled = 1; // LED is ON //wait(0.2); // 200 ms //myled = 0; // LED is OFF //wait(0.2); // 1 sec //oled.writeString(0, 0, "Hello World !"); //pc.printf("Printed something\r"); //wait(3); } } ichigojam用 10 'START 0.5 DATA 7BIT SOTP 1 20 OUT 11,1:WAIT 15 30 [0]=ASC("C") 40 [1]=ASC("H") 50 [2]=ASC("R") 60 [3]=ASC("I") 70 [4]=ASC("S") 80 [5]=ASC("T") 90 [6]=ASC("M") 100 [7]=ASC("A") 110 [8]=ASC("S") 120 [9]=ASC("_") 160 FOR I=0 TO 9 170 R=[I]:GOSUB 200:WAIT 60 180 NEXT 190 GOTO 160 200 ' 210 OUT 11,0:WAIT 1 220 FOR S=0 TO 6 230 OUT 11,!( (R >> S)&1 ) 240 WAIT 2 250 NEXT 260 OUT 11,1 270 WAIT 2 280 RETURN stm32f303k8 mbed側のプログラム 秋月の128x32のoled #include "mbed.h" #include "SSD1306.h" #include "font_8x8.h" DigitalOut myled(LED1); DigitalIn myin9(PF_1); // for out 11 (in4) (303 D8) #define ADDR (0x3c<<1) // address //#define ADDR (0x3d<<1) // address I2C i2c(I2C_SDA, I2C_SCL); // Host PC Communication channels Serial pc(USBTX, USBRX); // tx, rx // Instantiate OLED SSD1306 oled(i2c, ADDR); char ddff[8*8]; void char11(int row,int com,int cha) { int char_index1; char_index1 = cha-0x20; int ii; for (ii = 0;ii<(8*4);ii++) {ddff[ii]=0;} for (ii =0;ii<8;ii++){ ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 0) & 1)<<1; //1bit ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 0) & 1)<<3; //1bit ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 1) & 1)<<5; //2bit ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 1) & 1)<<7; //2bit ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 2) & 1)<<1; //3bit ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 2) & 1)<<3; //3bit ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 3) & 1)<<5; //4bit ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 3) & 1)<<7; //4bit ddff[ii+16] = ddff[ii+16] | ((font_8x8[char_index1][ii] >> 4) & 1)<<1; //5bit ddff[ii+16] = ddff[ii+16] | ((font_8x8[char_index1][ii] >> 4) & 1)<<3; //5bit ddff[ii+16] = ddff[ii+16] | ((font_8x8[char_index1][ii] >> 5) & 1)<<5; //6bit ddff[ii+16] = ddff[ii+16] | ((font_8x8[char_index1][ii] >> 5) & 1)<<7; //6bit ddff[ii+24] = ddff[ii+24] | ((font_8x8[char_index1][ii] >> 6) & 1)<<1; //7bit ddff[ii+24] = ddff[ii+24] | ((font_8x8[char_index1][ii] >> 6) & 1)<<3; //7bit ddff[ii+24] = ddff[ii+24] | ((font_8x8[char_index1][ii] >> 7) & 1)<<5; //8bit ddff[ii+24] = ddff[ii+24] | ((font_8x8[char_index1][ii] >> 7) & 1)<<7; //8bit }//for oled.writeBitmap((uint8_t*) ddff, row, (row + 4 - 1), com, (com + 8 - 1)); } //end chr11 int main() { int a; int b; int c; int d; int e; //5bit int f; //6bit int g; //7bit char s[2] = {'@',0}; int tl_f; int tls; int tl; int cursor1; int ii,jj; pc.baud(9600); myin9.mode( PullUp ); // 内蔵プルアップを使う // oled.writeString(0, 0, 13, "Hello World !"); //oled.writeString(0, 0, "Hello World !"); //char11(0,0,'H');char11(0,8,'e');char11(0,16,'l');char11(0,24,'l');char11(0,32,'o'); char ss1[]="Hello World !"; ii=0; while(ss1[ii]!=0){ char11(0,ii*8,ss1[ii]);ii++; } pc.printf("Printed something\r"); wait(3); // 1234567890123456 //oled.writeString(0, 0, "@ "); for(ii=0;ii<16;ii++){ char11(0,ii*8,' '); }//end for char11(0,0,'@'); e=0;f=0;g=0; tl = 33; //シリアル 1ビットの長さ cursor1 = 0; while(1) { tl_f = 0;tls=33; while( myin9 == 1 ) {} for(int loop_i=1;loop_i <= 33;loop_i++){ wait_ms(1);if(myin9 == 1 && tl_f == 0){tl_f=1;tls=loop_i*2;} } if(tl_f == 1) {tl = tls - 1;} // スタートビット目の次が1の場合と調整 //wait_ms(tl); //debug a=!(myin9); // 1bit wait_ms(tl); b=!(myin9); // 2bit wait_ms(tl); c=!(myin9); // 3bit wait_ms(tl); d=!(myin9); // 4bit 16 wait_ms(tl); e=!(myin9); // 5bit 32 wait_ms(tl); f=!(myin9); // 6bit 64 wait_ms(tl); g=!(myin9); // 6bit 64 wait_ms(tl); //a=0; // debug s[0]=g*64+f*32+e*16+d*8+c*4+b*2+a; if( s[0]=='_' ) { //画面クリア // 1234567890123456 //oled.writeString(0, 0, " "); for(jj=0;jj<2;jj++){ for(ii=0;ii<16;ii++){ char11(jj*4,ii*8,' '); }//end for }//enf for //カーソルのクリア cursor1 = 0; } else { //文字の表示 pc.printf(s); // y x //oled.writeString(0, cursor1, s); char11( (cursor1>>4)*4, ((cursor1-0) & 0x0f )*8, s[0]); cursor1++; //debug //s[0]='0'+(tl/10);oled.writeString(1, 0, s); //s[0]='0'+(tl%10);oled.writeString(1, 1, s); //debug //s[0]='0'+g;oled.writeString(2, 0, s); //s[0]='0'+f;oled.writeString(2, 1, s); //s[0]='0'+e;oled.writeString(2, 2, s); //s[0]='0'+d;oled.writeString(2, 3, s); //s[0]='0'+c;oled.writeString(2, 4, s); //s[0]='0'+b;oled.writeString(2, 5, s); //s[0]='0'+a;oled.writeString(2, 6, s); } if(cursor1 >= 32) { //画面クリア // 1234567890123456 //oled.writeString(0, 0, " "); for(jj=0;jj<2;jj++){ for(ii=0;ii<16;ii++){ char11(jj*4,ii*8,' '); }//end for }//end for //カーソルのクリア cursor1 = 0; } //endif //myled = 1; // LED is ON //wait(0.2); // 200 ms //myled = 0; // LED is OFF //wait(0.2); // 1 sec //oled.writeString(0, 0, "Hello World !"); //pc.printf("Printed something\r"); //wait(0.5); //debug } }