Check out a free preview of the full Hardware with Arduino & JavaScript course

The "Displaying System Information" Lesson is part of the full, Hardware with Arduino & JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Steve imports the "systeminformation" Node module and demonstrates how system information can be displayed on the LCD screen. Memory usage and battery percentage are two of the statistics shown.

Preview
Close

Transcript from the "Displaying System Information" Lesson

[00:00:00]
>> Clearly I think the fun with all this stuff comes into hooking into Node specific stuff. In that LCD folder, I got this other directory, but we can do it in here, where we can actually, there's a library in Node called system information. And really what it does, is it, like it's cross-platform, can read diagnostics about your system, right?

[00:00:28]
And so what we could do is we could pull that in, so we could say, import system from 'systeminformation'. Awesome, and then we wait for the board to get created and then on an interval or whatever, let's read it once and then we'll do the rest. You can look at the docs for this library.

[00:00:52]
It can tell you stuff, battery life, what your free amount of memory is. Depends on what operating system you're using too, you can get slightly different things from Linux and Windows than you can from Mac OS, but I picked two that were cross-platform. So what I'll do here is I'll say memory = await system.mem().

[00:01:15]
And we'll say, Battery will be the system battery. And then we'll just say, let's start with lcd.cursor. That's a lot information, lcd.cursor, and we'll say (0, 0), and we'll say print('Battery: ' + battery.percent). Sure, memory.used over memory.total, why not. Let's try that out and see how it goes for us.

[00:02:00]
You can currently see battery percent is a 100%. The memory is some large number that looks like I have a lot of memory on this computer. I might choose to divide that by a certain amount. Let's actually just do available, we'll do memory.available. And I'm gonna divide it by, 1024 divided by 1024, which is basically I'm taking bytes and turn it into megabytes.

[00:02:37]
I'm gonna do a Math.round in there too. So it's telling me the number of bytes which on a computer, I think this one has 32 gigabytes of memory, which is a lot. So we'll save that and we'll push it up. So now I can see that I've got 18,000 megabytes of free memory, and 100% battery cuz I'm plugged in, right?

[00:03:04]
So I can read that system information on load. I think this gets a little bit more interesting, though, if we update these values on an interval too. So I could say, setInterval. And put all that in there. I get to make an async function. And let's do that every, I don't know, second.

[00:03:37]
We'll push that up as well. Yep, and so now it is regularly updating my battery percentage in memory, which I can see changing as well.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now