Check out my first novel, midnight's simulacra!

InaMORAta: Difference between revisions

From dankwiki
Line 20: Line 20:
We'll need a digital input pin with interrupt support. On the Arduino Uno, this restricts us to pin 2 or 3. We use pin 2, plus the necessary resistor.
We'll need a digital input pin with interrupt support. On the Arduino Uno, this restricts us to pin 2 or 3. We use pin 2, plus the necessary resistor.


==Control (PWM)==
==Control==
===Fan PWM===
We set up a 25K PWM signal on pin 8. We can't use the standard Arduino PWM system, which operates at lower frequencies (490Hz and 980Hz). We operate directly on timer registers, using timer 4:
We set up a 25K PWM signal on pin 8. We can't use the standard Arduino PWM system, which operates at lower frequencies (490Hz and 980Hz). We operate directly on timer registers, using timer 4:
<pre>
<pre>
Line 35: Line 36:
   OCR4C = duty;
   OCR4C = duty;
</pre>
</pre>
===LEDs===
We use three PWM-capable digital pins: 9, 10, and 11 for blue, green, and red respectively. <tt>analogWrite()</tt> is sufficient to set the brightness. These pins are used to control logic level MOSFETs, which are also hooked up to ground and the 12V input.


==Temps==
==Temps==

Revision as of 05:29, 14 September 2022

Let's fuck hard with some fans using an Arduino MEGA and a Heltec LoRa ESP32 v2. These will be used with my MO-RA3 to collect realtime data (fan RPMs, temperatures, etc.) and provide realtime control (fan PWM/RPM, RGB signals).

We use a 12V PWM+DRGB hub for the many fans of the MO-RA3. Only one fan's RPM will be reported (whichever one is plugged into the red fan hookup), so it's important that we use the same model throughout. The hub has a two-wire hookup for tach and PWM (12V and ground are provided through the SATA power hookup). Looking at the hub with the clear side oriented up, the left wire is the PWM input, and the right wire is the tach output.

Communication

We'll want to report RPMs to the controlling host, and probably take PWM and RGB orders from it. We might use e.g. LoRa for this later. For now, we'll use MQTT over WiFi.

Powering the system

We need 12V for our fans (Arctic P14 RGBs) and their RGB LEDs. This is accomplished with a SHNITPWR 12V AC adapter, plugged into a barreljack switch. This barreljack switch is then adapted to a 12V-only SATA plug (SATA normally carries 3.3V, 5V, and 12V). The SATA plug enters a 12V PWM+RGB hub. All fans are plugged directly into this hub, one port of which carries through tachometer readings.

A 12V plus ground pair are used from one of the hub's PWM hookups to drive a HiLetgo LM2596 buck converter. The LM2596 is configured to deliver 7.1V by adjusting a potentiometer. The output is displayed on the LM2596's LED. This is a safe output to drive both the Arduino and the Heltec. On the output side, we hook two barreljack pushbutton connectors up to the LM2596. One directly powers the Arduino. The other uses a microUSB adapter to power the Heltec.

We will *not* be powering the fans or LEDs from the Arduino directly. They draw too many amps, and Arduinos can't provide 12V power directly anyway.

Everything else is powered by the hub directly. We only need 5V for the tachometer and PWM signals, but we need send 12V PWM to the LEDs. We thus connect another 12V plus ground pair to one side of the breadboard, where we'll feed it into MOSFETs.

Rotation count (RPMs)

Most case fans have a tachometer inside, using the third wire to send its signal. It will be strobed once for every two revolutions. If it is e.g. strobed 80 times within a second, then there were 160 revolutions in that second, and we can extrapolate to 9600RPM (truly an insane case fan; I know of no such monstrosities).

We'll need a digital input pin with interrupt support. On the Arduino Uno, this restricts us to pin 2 or 3. We use pin 2, plus the necessary resistor.

Control

Fan PWM

We set up a 25K PWM signal on pin 8. We can't use the standard Arduino PWM system, which operates at lower frequencies (490Hz and 980Hz). We operate directly on timer registers, using timer 4:

  const word PWM_FREQ_HZ = 25000;
  TCCR4A = 0;
  TCCR4B = 0;
  TCNT4  = 0;
  ICR4 = (F_CPU / PWM_FREQ_HZ) / 2;
  TCCR4A |= (1 << COM4A1) | (1 << WGM41);
  TCCR4B |= (1 << WGM43) | (1 << CS40);

This ICR4 value comes out to 320. We can then set the desired PWM duty (0–255) with:

  OCR4C = duty;

LEDs

We use three PWM-capable digital pins: 9, 10, and 11 for blue, green, and red respectively. analogWrite() is sufficient to set the brightness. These pins are used to control logic level MOSFETs, which are also hooked up to ground and the 12V input.

Temps

We want the water temperature, and ideally also our own temperature on the microcontroller. The Uno's ATmega328P processor has an onboard temperature sensor:

int readTemp(void){
  ADCSRA |= _BV(ADSC);
  while(bit_is_set(ADCSRA, ADSC)){
    ;
  }
  return (ADCL | (ADCH << 8)) - 342;
}

Unlike the Uno, it appears that the MEGA has no way to get its own temperature, lame.

External (thermistor)

We're using an Alphacool Eiszapfen 17365 plug sensor. Its datasheet can be found here. This is a 10kΩ thermistor (resistance varies with temperature) with a β of 3435K and a nominal temperature of 25℃. To effect a better read, we'll use the 3.3V as our reference. This requires hooking 3.3V up to AREF and calling analogReference(EXTERNAL);. We pair it with a reference 10KΩ resistor, and hook it up to 3.3V, ground, and analog input pin A0.

Wiring

  • 5V pin goes to 10kΩ resistor, goes to tach signal
  • Take ground from power source
  • Analog input pin goes to thermistor signal
  • Digital output pin 8 goes to PWM input
  • 3.3V pin goes to 10kΩ resistor, goes to thermistor signal
  • 3.3V goes to AREF

Example breadboard

  • 1A: digital input pin supporting interrupts (2 or 3 on the Uno)
  • 1B: tachometer signal
  • 1C: 7C
  • 2D: Arduino GND
  • 7B: 10kΩ resistor
  • 7C: 1C
  • 16A: 5V
  • 16B: 10kΩ resistor

Protocol