-1

I am interested in building a basic CPU usage monitor with arduino UNO.

I have a Ruby code, which blinks keyboard lights based on the CPU usage, disk IO and net usage.

So for example, when the CPU usage is high, it will write 1 to all the keyboards from /sys/class/leds/input*::capslock/brightness

I want to do the similar thing to the arduino, is there a way to read USB data pins and control the light without recompiling and re-uploading code every time? So on my laptop a C Ruby (libusb), C, etc code can run, and with that I can control the Arduino UNO.

1
  • 2
    With the Uno you would need to rewrite your ruby code to send data over the Unos Serial interface. On the Uno you can then put a code, that reads that data and blinks the LED accordingly. The Unos program is to be programmed once. It stays in the Unos flash memory persistently. You only need to reprogram, when your code changes. – chrisl Apr 16 at 7:56
1

Have your Ruby code send an ASCII digit representing the display values for the variables you want the Uno to display. Since the Uno has only one LED you can program, you'll need two more to display all three variables.

Each time the Uno receives a new data triplet, convert each digit to whatever means of display you choose to represent those values - blink frequency or duty-cycle, for example.

You'll want to write a non-blocking program that just keeps updating the LEDs regardless of whatever else is going on, such as interpreting the next triplet. Look at the Blink Without Delay example program in the Arduino IDE. Also look here on Arduino Stack Exchange for questions/answers about non-blocking programming techniques (you might even find one written by me). Your most important take-away should be: don't use delay().

I suggested sending 3 ASCII digits - you could send binary instead. But ASCII will simplify testing both your Ruby and your Arduino code, separately at first, since the communication from Ruby will be human-readable, and the commands to Uno can be human-generated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.