gobeng
December 28, 2022, 10:28pm
#1
Which version of system do you use? Khadas official images, self built images, or others?
Khadas official image ubuntu server
uname
Linux
uname -r
5.4.180
Connected to i2cm_a and enabled the i2cm interface
Please describe your issue below:
I am trying to show data on a i2c oled display (https://www.amazon.co.uk/gp/product/B093KHHKVM/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&th=1 ) but I do not get anything on the screen. I am using the WiringPi library.
Below is the code I am using.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <wiringPiI2C.h>
#include <wiringPi.h>
#include "lcd128x64.h"
#define DEVICE_ID 0x3C
int main (int argc, char **argv)
{
// Setup I2C communication
int fd = wiringPiI2CSetup(DEVICE_ID);
if (fd == -1) {
printf("Failed to init I2C communication.\n");
return -1;
}
printf("I2C communication successfully setup.\n");
fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x3C);
if (fd == -1) {
printf("Failed to set I2C interface.\n");
return -1;
}
printf("I2C interface successfully setup.\n");
while (1) {
lcd128x64setup();
lcd128x64clear(0);
}
return 0;
}
Post a console log of your issue below:
I2C communication successfully setup.
I2C interface successfully setup.
i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
numbqq
December 29, 2022, 1:10am
#2
Hello @gobeng
How about this one ?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <wiringPiI2C.h>
#include <wiringPi.h>
#include "lcd128x64.h"
#define DEVICE_ID 0x3C
int main (int argc, char **argv)
{
// Setup I2C communication
int fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x3C);
if (fd == -1) {
printf("Failed to set I2C interface.\n");
return -1;
}
printf("I2C interface successfully setup.\n");
while (1) {
lcd128x64setup();
lcd128x64clear(0);
}
return 0;
}
gobeng
December 29, 2022, 2:33am
#3
Hello @numbqq thanks for the quick reply
Made some changes as well but I am still not getting anything on the screen
int main (int argc, char **argv)
{
// Setup I2C communication
int fd = wiringPiI2CSetupInterface(“/dev/i2c-0”, 0x3C);
if (fd == -1) {
printf(“Failed to set I2C interface.\n”);
return -1;
}
printf("I2C interface successfully setup.\n");
int status = lcd128x64setup();
if (status != 0) {
printf("Failed to set lcd.\n");
return -1;
}
printf("LCD setup. \n");
while (1) {
lcd128x64puts(4, 4, "Test\nThis\n", 1, 0);
}
return 0;
}
I have tried using the original lcd128x64.h built into the vim4
numbqq
December 29, 2022, 3:15am
#4
Hello @gobeng
Please try to write and read one byte from the register to check wether the value is correct or not.
gobeng
December 29, 2022, 3:46am
#5
Hello @numbqq
regardless of what I put I keep getting these numbers
fd before = 3
fd after = 3
status = 67
Code:
int main (int argc, char **argv)
{
int fd = 0;
int status = 0;
// Setup I2C communication
fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x3C);
if (fd == -1) {
printf("Failed to set I2C interface.\n");
return -1;
}
printf("I2C interface successfully setup.\n");
status = lcd128x64setup();
if (status != 0) {
printf("Failed to set lcd.\n");
return -1;
status = 0;
}
printf("LCD setup. \n");
printf("fd before = %d \n", fd);
wiringPiI2CWrite(fd, 4);
status = wiringPiI2CRead(fd);
printf("fd after = %d \n", fd);
printf("status = %d \n", status);
return 0;
}
gobeng
December 30, 2022, 1:43am
#6
Hello @numbqq
I just found this out. Do you know what could be causing it?
root@vim4:~# cat /boot/overlays/kvim4.dtb.overlay.env
fdt_overlays=i2cm_a i2cm_f
root@vim4:~# gpio readall
+------+-----+----------+------+---+----+----- Model Khadas VIM4 --+----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
| | | 5V | | | | | 1 || 21 | | | | | GND | | |
| | | 5V | | | | | 2 || 22 | DSBLD | | 1 | ALT0 | PIN.Y17 | 6 | 501 |
| | | HUB_D4N | | | | | 3 || 23 | DSBLD | | 1 | ALT0 | PIN.Y18 | 7 | 502 |
| | | HUB_D4P | | | | | 4 || 24 | | | | | GND | | |
| | | GND | | | | | 5 || 25 | DSBLD | | 1 | ALT1 | PIN.T20 | 8 | 466 |
| | | VCCMCU | | | | | 6 || 26 | DSBLD | | 1 | ALT1 | PIN.T21 | 9 | 467 |
| | | MCUBOOT0 | | | | | 7 || 27 | | | | | 3V3 | | |
| | | MCUSWDIO | | | | | 8 || 28 | | | | | GND | | |
| | | GND | | | | | 9 || 29 | P/D | | 0 | IN | PIN.T1 | 10 | 447 |
| | 19 | ADC_CH6 | | | | | 10 || 30 | P/D | | 0 | IN | PIN.T0 | 11 | 446 |
| | | VDD1V8 | | | | | 11 || 31 | P/D | | 0 | IN | PIN.T3 | 12 | 449 |
| | 20 | ADC_CH3 | | | | | 12 || 32 | P/D | | 0 | IN | PIN.T2 | 13 | 448 |
| 420 | 1 | SPDIFOUT | IN | 0 | | P/D | 13 || 33 | P/D | | 0 | IN | PIN.T4 | 14 | 450 |
| | | GND | | | | | 14 || 34 | | | | | GND | | |
| 491 | 2 | PIN.Y7 | IN | 0 | | P/D | 15 || 35 | P/D | | 0 | IN | PIN.Y8 | 15 | 492 |
| 490 | 3 | PIN.Y6 | IN | 1 | | P/U | 16 || 36 | P/D | | 0 | IN | PIN.T18 | 16 | 464 |
| | | GND | | | | | 17 || 37 | P/D | | 0 | IN | PIN.T19 | 17 | 465 |
| 413 | 4 | PIN.D1 | ALT0 | 1 | | P/U | 18 || 38 | | | | | PWR_EN1 | | |
| 414 | 5 | PIN.D2 | ALT0 | 1 | | DSBLD | 19 || 39 | P/U | | 1 | IN | PIN.D5 | 18 | 417 |
| | | 3V3 | | | | | 20 || 40 | | | | | GND | | |
+------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+