en-us_commands:reference:ianalogwrite2f
Table of Contents
IanalogWrite2f()
IanalogWrite2f() converts a user floating-point value to the 4~20mA output range.
void IanalogWrite2f(uint8_t ch, float min, float max, float value)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
IanalogWrite2f(ch, min, max, value) | uint8_t ch — MPINO: analog pin such as A0; MPAINO: overall module channel number starting at 0float minfloat maxfloat value — Output value expressed in the min ~ max range | void | Converts a user floating-point value to the 4~20mA output range. |
Example
Connect a Y output module to MPAINO-8A8R(T) and select Analog Output Module → Y. Set the CH0 DIP switch to OFF and measure the 4–20mA output at I+ and −.
void setup() {} void loop() { IanalogWrite2f(0, 0.0F, 100.0F, 25.0F); // Scale 25% to the 4–20mA range and output about 8mA. delay(500); }
Precautions
- Set the MPAINO Y module CH0 DIP switch to OFF and connect the 4–20mA output to
I+and−. - An input of approximately 3.6~4.0mA returns the normal value
0; inputs below 3.6mA return an error value. - Error values help detect open circuits. The user must implement final alarms and safety actions in the program.
IanalogRead2()andIanalogRead2f()also return65535on error, rather than a user-range value. Check for errors before using the result.- The full
int32_trange is available formin~maxinIanalogRead2(), but if the normal range includes65535, it cannot be distinguished from an error value. analogRead2Avgf()uses state and a buffer separate fromanalogRead2Avg(). Using both increases SRAM usage.- If
samplesis0or memory allocation fails inanalogRead2Avgf(), it returns the current valid corrected value as afloat. - On MPINO, do not use
analogRead2()on voltage/NTC channels that are not 4~20mA inputs. - For MPINO products requiring
analogReference(EXTERNAL), set it first insetup(). IanalogWrite2()andIanalogWrite2f()are convenience outputs dedicated to 4~20mA. Avoid alternating them withIanalogWrite()on the same channel.- The analog output circuit requires an external 12~24V supply. USB power alone may not provide normal output.
- Verify actual current input/output with measuring instruments after preparing a test product.
Built-in Commands in the Same Category
en-us_commands/reference/ianalogwrite2f.txt · Last modified: by 127.0.0.1
