Giter Club home page Giter Club logo

Comments (17)

scockman avatar scockman commented on May 21, 2024 1

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

from u6143_ssd1306.

robiwisc avatar robiwisc commented on May 21, 2024

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.

from u6143_ssd1306.

scockman avatar scockman commented on May 21, 2024

I also have the pi4 8GB and it is showing 0.

from u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

Same problem here with 8GB Raspberry PI. I have 2 - 4GB that show correct Memory and usage. Could this be 64 bit related?

from u6143_ssd1306.

alpayne avatar alpayne commented on May 21, 2024

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 u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

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.

from u6143_ssd1306.

robertalexa avatar robertalexa commented on May 21, 2024

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.

from u6143_ssd1306.

robertalexa avatar robertalexa commented on May 21, 2024

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

from u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

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

from u6143_ssd1306.

robertalexa avatar robertalexa commented on May 21, 2024

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

from u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

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.

from u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

from u6143_ssd1306.

robertalexa avatar robertalexa commented on May 21, 2024

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.

from u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

from u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

from u6143_ssd1306.

screch1 avatar screch1 commented on May 21, 2024

from u6143_ssd1306.

robertalexa avatar robertalexa commented on May 21, 2024

@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

from u6143_ssd1306.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.