🚧 blog links: use Node. Js wrote a console to raspberries pie | Amber

I bought a lot of raspberry pie when I was a freshman, because I didn’t know anything at that time, so I spent most of my time eating ashes in the corner. Recently, I saw an article about a foreign brother building a Hadoop cluster with raspberries, so I took out the raspberry PI and re-transformed it to be used as a smart home center. The good news is that the original Lego shell is easy to refurbish and now looks like the one below. I chose HomeAssistant as my smart home hub in order to be able to control several Xiaomi smart lights in my home using HomeKit on iOS, but the heat dissipation of the Raspberry PI was a problem.

Snow is safe from bugs

I originally bought raspberry PI with fans, but they are directly plugged into the raspberry PI power supply interface, that is to say, 3.3V POWER SUPPLY GPIO pin can not drive 5V fan, and on the other hand, the small fan is very noisy, and the whole day and night open shaft can not bear (already hanging one), So I went to one of Vaneng’s stores and bought a well-built maglev fan with a 6cm wind diameter that could cool two raspberry PI’s at the same time. The fact proves that magnetic levitation fan really lives up to its reputation, the wind volume is really no sound. But in order to prolong the life of bearing shaft, it is necessary to design a fan control program which can be controlled by programming.

After some searching, I referred to this article. As mentioned above, 3.3V GPIO cannot directly power the fan, so I chose the triode scheme in Bowen and designed the circuit like this:

CircuteLab doesn’t have motor online, so lamp will do

I chose the PNP triode of S9012 as mentioned in the blog, the positive fan is connected to the raspberry PI 5V pin, the negative is connected to the triode emitter, the triode base is connected to the GPIO pin you want to use (for example, I have pin 8 (GPIO 14)), and the collector is grounded. Refer to the raspberry PI pin diagram below:

⚠️ Note that the rPIO pin number does not correspond exactly to the actual GPIO port number, as described below

Next, the fan is programmed to stop automatically by Node.js. Node.js is used for easy console interworking with the following code:

const GPIO = require('rpio')
const PIN = 8 // Pin 8 here corresponds to GPIO 14. For the rest, please refer to the RPI GPIO manual: https://pinout.xyz/
const TEMP_LOW = 38 // Stop operation below 38 ° C
const TEMP_HIGH = 42 // Turn on the fan when the temperature is higher than 42 degrees Celsius

const TEMP_FILE = '/sys/class/thermal/thermal_zone0/temp'

Return {Number} Current temperature */
function cpuTemp () {
  return parseFloat(require('fs').readFileSync(TEMP_FILE)) / 1000
}

setInterval(function () {
  temp = cpuTemp()
  console.log(`Current temp is ${temp}`)
  if (isClose) {
    if (temp > TEMP_HIGH) {
      GPIO.write(PIN, GPIO.LOW)
      console.log('Open air cooler')
      isClose = false}}else {
    if (temp < TEMP_LOW) {
      GPIO.write(PIN, GPIO.HIGH)
      console.log('Close air cooler')
      isClose = true}}},2000) // Refresh every 2s
Copy the code

Oh, there’s a hole I forgot to mention. Including my reference of the blog, most of the information on the network are through to the interface of high level to turn on the fan, but in fact it is calculated on the NPN transistor, the result of the work to make the PNP to enlarge state should launch knot is partial and collector junction reverse slants, if GPIO pins at this time give high level cannot make normal work of the triode, That’s why it’s low here.

To test this, I dug out the dusty ebook and reviewed it.

Using Node to write the console backend is relatively simple, the main architecture is Express as the server, bootstrap Materialize Design + D3. js as the front-end page, and then through sock. IO as WebSocket communication. Although simple, but the code is tedious, I will not post it here, to give a few screenshots of the meaning:

Your browser doesn’t seem to support the

Sexy fan online flirting

It is best served with home Sistant

However, I don’t know if it’s d3.js, but the performance is not very good now. After running for a long time, the Raspberry PI is not hot, but the CPU of the computer is foggy. It is estimated that the cost of repeatedly operating DOM performance is still too high, so I will use Vue for reconstruction next year.

Refer to the link

  • Build a Raspberry Pi Hadoop Cluster to Run Spark on YARN – DQYDJ
  • Raspberry PI starts and stops fans based on CPU temperature