Open almulder opened 3 years ago
It's displaying fine on my pi4 4GB. I have a pi4 8GB coming Thursday. I'll test it out and see if I get the MEM 0 error.
I also have the pi4 8GB and it is showing 0.
Same problem here with 8GB Raspberry PI. I have 2 - 4GB that show correct Memory and usage. Could this be 64 bit related?
4GB and 8GB models running 64-bit Ubuntu server both display properly, so not likely 64-bit related.
For those with the problem, what OS are you running?
From Raspberry-Pi OS:
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=raspbian ID_LIKE=debian
UPDATE: Linux version 5.10.17-v7l+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1403 SMP Mon Feb 22 11:33:35 GMT 2021
I believe this is the 32-bit version as the 64-bit is still in beta correct? Hopefully that helps. Kind of new at this but learning something new everyday, Thanks for the assistance in advance.
After finally getting my other issue with running this under Ubuntu, I am using @robiwisc fork and using his C_HostName_IP version and with that it has resolved my zero memory issue.
Running Ubuntu 20.04.2 LTS on Raspberry Pi 4 8GB
I am having the same issue on Raspbian on a 4GB rpi 4.
I am starting to wonder if this has anything to do with Raspbian being Lite version?
I have tried to debug the code and sysinfo is not throwing an error, but it is returning values of 0.000000, hence what we are seeing.
I will keep digging.
After some investigation I have managed to find the answer to this problem. Before I start, I am using my own fork, which was forked from @robiwisc for using the Hostname. In my fork I have also done some more fixes and included a service based on a PR on this original repo (I have basically consolidated all the missing bits into my fork)
The memory was showing up correctly on my Ubuntu 20.04, but on on my RPI running the latest kernel.
So i suspected some differences. From the manual of sysinfo:
` Until Linux 2.3.16, sysinfo() returned information in the following structure:
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* Swap space still available */
unsigned short procs; /* Number of current processes */
char _f[22]; /* Pads structure to 64 bytes */
};
In the above structure, the sizes of the memory and swap fields
are given in bytes.
Since Linux 2.3.23 (i386) and Linux 2.3.48 (all architectures)
the structure is:
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* Swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)];
/* Padding to 64 bytes */
};
In the above structure, sizes of the memory and swap fields are
given as multiples of mem_unit bytes.
` The thing to take from there is that in newer versions, memory size is not returned as bytes anymore but instead in multiples of mem_unit.
In my case, on Ubuntu, mem_unit is 1, and on RPI, mem_unit is 4096. So you can now see how if you divide a smalled number by the same number, you end up with a result so small that it get rounded up to 0, which is what we were seeing 0.0 / 0.0
I have corrected the code in ssd1306_i2c.c by changing 2 lines
Totalram=s_info.totalram*s_info.mem_unit/1024/1024/1024.0; freeram=s_info.freeram*s_info.mem_unit/1024/1024/1024.0;
So I multiple s_info.totalram (and freeram) by the actual s_info.mem_unit.
This does indeed fix the issue, however I am not pleased with the outcome at all, but that is because of how sysinfo actually works, and how Linux actually handles available ram.
To explain: The screen shows 0.2/3.7G
htop used memory 1.27G total memory 3.74G
so available memory is 2.47G
top available memory 215M total 3826M buff/cache 2358M
So if you calculate real available memory is 2573M (close to htop)
But as you can see, available memory on the screen matches available memory in top, so it is technically correct.
However Linux by it's nature doesn't like unused ram, so instead it caches and buffers it, and makes it available as soon as an app needs it. So it is "used" but it isn't really.
The sysinfo API does cache for bufferram but nothing about cache, so even if I include it, it will still be off by a lot.
With that in mind I plan on re-writing it completely to use /proc/meminfo instead - in your terminal type cat /proc/meminfo to see results. In my case:
MemTotal: 3918108 kB MemFree: 216068 kB MemAvailable: 2788288 kB Buffers: 57588 kB Cached: 2306240 kB
You can now see what I was mentioning above. If you sum MemFree + Buffers + Cached you get MemAvailable.
I will do this soon and it will be pushed in my fork.
I will be more than happy for you guys to use my fork or even backport changes to your owns if you so desire.
Please let me know what you think of the above and if it all works for you.
PS: don't forget to recompile after changing the code.
Rob
This is GREAT, you are smart!! I tried it and now the memory shows up on the OLED display. Although the problem now relates to showing 4GB versus 8GB.
See TOP below from my RPi:
MiB Mem : 7924.7 total, 7491.0 free, 80.7 used
I also ran the command above from your info and got this: MemTotal: 8114860 kB MemFree: 7666672 kB MemAvailable: 7784424 kB Buffers: 41096 kB Cached: 308748 kB
Would you change the 1024 and add more for the 8GB? I am not a programmer or coder but seems logical to me although I could be way off on this. :)
Thanks for all the investigation and information your provided. You should send this over to Uctronics and they should thank you for fixing the code.
Thoughts for the 8GB memory?
Fred
Hey Fred,
Start with the simple things. I don't think UCTRONICS are still properly looking after this, but i might be wrong. Here is my repo https://github.com/robertalexa/U6143_ssd1306 The fix is only done currently on the C_HostName_IP version. This shows Hostname at the top at all times and then the IP is part of the scroll.
Back to the issue: the 1024 division is to convert the values to GB so adding more will change it to TB instead, nothing to do with how much RAM you have. This should just work.
What can you see on your display though?
Rob
I see 3.2 used and 3.7 available but I just modified the file version I had when I found those lines, although I will try to use your fork and see what the outcome is. Learning something new everyday. Who knows I could have done something wrong but I guess this is the process of learning. Thanks for the quick reply.
Thanks for the response. This is actually interesting to me to try to figure out. I will bet you will figure this out well before me.
From: Robert Alexa @.> Sent: Thursday, May 6, 2021 5:41 PM To: UCTRONICS/U6143_ssd1306 @.> Cc: screch1 @.>; Comment @.> Subject: Re: [UCTRONICS/U6143_ssd1306] Mem shows 0.0 / 0.0GB (#3)
I am having the same issue on Raspbian on a 4GB rpi 4.
I am starting to wonder if this has anything to do with Raspbian being Lite version?
I have tried to debug the code and sysinfo is not throwing an error, but it is returning values of 0.000000, hence what we are seeing.
I will keep digging.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FUCTRONICS%2FU6143_ssd1306%2Fissues%2F3%23issuecomment-833887406&data=04%7C01%7C%7Ca4f03eb74dae45ca12c708d910d7c540%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559341172465509%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=gPFEfutg3YK%2FJDq2yOx4BZTslBz70JoUbsKwreA3pFc%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FATYD4ZAIAQF5VHZY3ZRMNRLTMMEKHANCNFSM42LBXAKQ&data=04%7C01%7C%7Ca4f03eb74dae45ca12c708d910d7c540%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559341172475472%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=t4iZdrgjgv6xI5ra9ruoQxt7O%2BAgRZsaaUi4Sx1ZSDA%3D&reserved=0.
And I am back again.
I have re-writen the above approach to use /proc/meminfo data calculated as such:
MemUsed = MemTotal - MemFree - Buffers - Cached
This is available in my fork.
The display will now show Used / Total in GB, aproximated to 1 decimal place - there was not enough room on the screen for 2 decimals unfortunately. In my case it shows 1.3 / 3.7 while htop shows 1.25 / 3.74
In my book this is a win and much more accurate then before.
Feel free to clone my fork and give it a try if you want, and if you experience anything weird create an issue there and I will try to assist, but please bear in mind that I am not really proficient in C (I come from a LAMP background) nor do i plan to make WOW features with this screen. I am happy with how it currently is, as long as it isn't broken :)
Rob
LE: I on purpose chose not to do error handling in the process of opening and parsing the file. If anyone runs an OS so old that /proc/meminfo doesn't contain all the required info, they should considered moving forward with technology.
This works great and is now correct for 8GB. Correct the other 2 forks? I use the one the original one without host name just the IP that would be awesome!!! I used the one corrected to test the memory portion to see if it worked.. and it did. Awesome job. If you correct all three I will oput it out to a few other friend that this worked and tell them to use it too. THANKS!
From: Robert Alexa @.> Sent: Friday, May 7, 2021 9:40 AM To: UCTRONICS/U6143_ssd1306 @.> Cc: screch1 @.>; Comment @.> Subject: Re: [UCTRONICS/U6143_ssd1306] Mem shows 0.0 / 0.0GB (#3)
And I am back again.
I have re-writen the above approach to use /proc/meminfo data calculated as such: MemUsed = MemTotal - MemFree - Buffers - Cached
This is available in my fork.
The display will now show Used / Total in GB, aproximated to 1 decimal place - there was not enough room on the screen for 2 decimals unfortunately. In my case it shows 1.3 / 3.7 while htop shows 1.25 / 3.74
In my book this is a win and much more accurate then before.
Feel free to clone my fork and give it a try if you want, and if you experience anything weird create an issue there and I will try to assist, but please bear in mind that I am not really proficient in C (I come from a LAMP background) nor do i plan to make WOW features with this screen. I am happy with how it currently is, as long as it isn't broken :)
Rob
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FUCTRONICS%2FU6143_ssd1306%2Fissues%2F3%23issuecomment-834401421&data=04%7C01%7C%7C5e8668d46bdd401edd1d08d9115dba5e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559916515528809%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=G%2F0rtRkKdv7Gg0G%2F4iLftKD2ACWjSJxhyvijytcjpZE%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FATYD4ZAUQDY5HNKANCFOI73TMPUWDANCNFSM42LBXAKQ&data=04%7C01%7C%7C5e8668d46bdd401edd1d08d9115dba5e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559916515528809%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IYcT5hx%2FngXwkA5AUUTWzh76AZoOCurZHK56d70v8rw%3D&reserved=0.
When I run make command I get a bunch of errors on the base code. See below:
@.:~/U6143_ssd1306/C $ make
cc -c -o display.o display.c
cc -c -o ssd1306_i2c.o ssd1306_i2c.c
ssd1306_i2c.c:289:6: error: redefinition of ‘LCD_DisPlayCpuMemory’
void LCD_DisPlayCpuMemory(void)
^~~~~~~~
ssd1306_i2c.c:240:6: note: previous definition of ‘LCD_DisPlayCpuMemory’ was here
void LCD_DisPlayCpuMemory(void)
^~~~~~~~
ssd1306_i2c.c: In function ‘LCD_DisPlayCpuMemory’:
ssd1306_i2c.c:291:18: error: storage size of ‘s_info’ isn’t known
struct sysinfo s_info;
^~
ssd1306_i2c.c:296:6: warning: implicit declaration of function ‘sysinfo’; did you mean ‘sysconf’? [-Wimplicit-function-declaration]
if(sysinfo(&s_info)==0) //Get memory information
^~~
sysconf
ssd1306_i2c.c: In function ‘LCD_Display’:
ssd1306_i2c.c:374:7: warning: implicit declaration of function ‘LCD_DisplayTemperature’; did you mean ‘LCD_DisplaySdMemory’? [-Wimplicit-function-declaration]
LCD_DisplayTemperature();
^~~~~~
LCD_DisplaySdMemory
make: [
From: Fred Guaraldo @.> Sent: Friday, May 7, 2021 10:48 AM To: UCTRONICS/U6143_ssd1306 @.> Subject: Re: [UCTRONICS/U6143_ssd1306] Mem shows 0.0 / 0.0GB (#3)
This works great and is now correct for 8GB. Correct the other 2 forks? I use the one the original one without host name just the IP that would be awesome!!! I used the one corrected to test the memory portion to see if it worked.. and it did. Awesome job. If you correct all three I will oput it out to a few other friend that this worked and tell them to use it too. THANKS!
From: Robert Alexa @.> Sent: Friday, May 7, 2021 9:40 AM To: UCTRONICS/U6143_ssd1306 @.> Cc: screch1 @.>; Comment @.> Subject: Re: [UCTRONICS/U6143_ssd1306] Mem shows 0.0 / 0.0GB (#3)
And I am back again.
I have re-writen the above approach to use /proc/meminfo data calculated as such: MemUsed = MemTotal - MemFree - Buffers - Cached
This is available in my fork.
The display will now show Used / Total in GB, aproximated to 1 decimal place - there was not enough room on the screen for 2 decimals unfortunately. In my case it shows 1.3 / 3.7 while htop shows 1.25 / 3.74
In my book this is a win and much more accurate then before.
Feel free to clone my fork and give it a try if you want, and if you experience anything weird create an issue there and I will try to assist, but please bear in mind that I am not really proficient in C (I come from a LAMP background) nor do i plan to make WOW features with this screen. I am happy with how it currently is, as long as it isn't broken :)
Rob
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FUCTRONICS%2FU6143_ssd1306%2Fissues%2F3%23issuecomment-834401421&data=04%7C01%7C%7C5e8668d46bdd401edd1d08d9115dba5e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559916515528809%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=G%2F0rtRkKdv7Gg0G%2F4iLftKD2ACWjSJxhyvijytcjpZE%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FATYD4ZAUQDY5HNKANCFOI73TMPUWDANCNFSM42LBXAKQ&data=04%7C01%7C%7C5e8668d46bdd401edd1d08d9115dba5e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559916515528809%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IYcT5hx%2FngXwkA5AUUTWzh76AZoOCurZHK56d70v8rw%3D&reserved=0.
Hello Robert,
I appreciate your efforts and this is great. I tried using you /C only which is basically the original with your memory changes and I get the following error when compiling.
@.*:~/U6143_ssd1306/C $ sudo make clean && sudo make
rm -rf .o
rm -rf display
cc -c -o display.o display.c
cc -c -o ssd1306_i2c.o ssd1306_i2c.c
ssd1306_i2c.c:289:6: error: redefinition of ‘LCD_DisPlayCpuMemory’
void LCD_DisPlayCpuMemory(void)
^~~~~~~~
ssd1306_i2c.c:240:6: note: previous definition of ‘LCD_DisPlayCpuMemory’ was here
void LCD_DisPlayCpuMemory(void)
^~~~~~~~
ssd1306_i2c.c: In function ‘LCD_DisPlayCpuMemory’:
ssd1306_i2c.c:291:18: error: storage size of ‘s_info’ isn’t known
struct sysinfo s_info;
^~
ssd1306_i2c.c:296:6: warning: implicit declaration of function ‘sysinfo’; did you mean ‘sysconf’? [-Wimplicit-function-declaration]
if(sysinfo(&s_info)==0) //Get memory information
^~~
sysconf
ssd1306_i2c.c: In function ‘LCD_Display’:
ssd1306_i2c.c:374:7: warning: implicit declaration of function ‘LCD_DisplayTemperature’; did you mean ‘LCD_DisplaySdMemory’? [-Wimplicit-function-declaration]
LCD_DisplayTemperature();
^~~~~~
LCD_DisplaySdMemory
make: [
Is this a fixable problem. I did go ahead and use the version with hostname and IP and that worked although my IP always shows up with 0.0.0.0 which does not make sense but you woul dknow better than me. Can the /C code be fixed and i will just usse that with your memory fix which is really what I want with the standard display. Any thoughts? Thanks and stay safe and take care.
-Fred
From: Robert Alexa @.> Sent: Friday, May 7, 2021 9:40 AM To: UCTRONICS/U6143_ssd1306 @.> Cc: screch1 @.>; Comment @.> Subject: Re: [UCTRONICS/U6143_ssd1306] Mem shows 0.0 / 0.0GB (#3)
And I am back again.
I have re-writen the above approach to use /proc/meminfo data calculated as such: MemUsed = MemTotal - MemFree - Buffers - Cached
This is available in my fork.
The display will now show Used / Total in GB, aproximated to 1 decimal place - there was not enough room on the screen for 2 decimals unfortunately. In my case it shows 1.3 / 3.7 while htop shows 1.25 / 3.74
In my book this is a win and much more accurate then before.
Feel free to clone my fork and give it a try if you want, and if you experience anything weird create an issue there and I will try to assist, but please bear in mind that I am not really proficient in C (I come from a LAMP background) nor do i plan to make WOW features with this screen. I am happy with how it currently is, as long as it isn't broken :)
Rob
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FUCTRONICS%2FU6143_ssd1306%2Fissues%2F3%23issuecomment-834401421&data=04%7C01%7C%7C5e8668d46bdd401edd1d08d9115dba5e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559916515528809%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=G%2F0rtRkKdv7Gg0G%2F4iLftKD2ACWjSJxhyvijytcjpZE%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FATYD4ZAUQDY5HNKANCFOI73TMPUWDANCNFSM42LBXAKQ&data=04%7C01%7C%7C5e8668d46bdd401edd1d08d9115dba5e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637559916515528809%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IYcT5hx%2FngXwkA5AUUTWzh76AZoOCurZHK56d70v8rw%3D&reserved=0.
@screch1 Hey man, sorry, I have completely lost track of this. You should have created an issue under my fork rather than here.
Anyway, I have now fixed it. Pull from my repo and should you have any problems create an issue there.
Here is my fork for quick access https://github.com/robertalexa/U6143_ssd1306
The IP address works if the device is connected via Ethernet eth0. If you still have issues with that and it shows 0.0.0.0 create an issue (in my repo) and i can try to help you
The display shows MEM but always 0. I have the pi4 8GB.