HID-Compliant UPS with Arduino

Simulating HID-compliant UPS with help of Arduino.

Oct 30, 2020

45076 views

5 respects

Components and supplies

1

Arduino Pro Micro

1

Jumper wires (generic)

1

Breadboard (generic)

Apps and platforms

1

Network UPS Tools Library

Project description

Downloadable files

Schema for testing Arduino UPS

Schema for testing Arduino UPS

Schema for testing Arduino UPS

Schema for testing Arduino UPS

Comments

Only logged in users can leave comments

linkinpio

5 months ago

@abratchik you did a great job with this project, I'm sure many people benefited from your work, but I am banging my head on one issue for some time now and can't get past that. I am using Arduino Pro Micro (it's a chinese clone) trying to get it working on proxmox host and had to change the HW id from ID 1b4f:9206 SparkFun SparkFun Pro Micro to ID 2341:8036 Arduino SA Leonardo (CDC ACM, HID) by using Leonardo board type as when using SparkFun # nut-scanner -U would not even detect the board. Also tried ussing SparkFun Pro Micro board with modifed ID 2341:8036 it would detect it but would give same error. After some troubleshooting I had to disable CDC by modifying boards.txt by adding "-DCDC_DISABLED" to extra flags leonardonocdc.build.extra_flags=-DCDC_DISABLED {build.usb_flags} and this made usbhid-ups detect the ups config but getting 0.008883 Can't claim USB device [2341:8036]@2/0: Invalid parameter error and can't seems to get passed it, here is the relevant config/output, please help me as I am stuck root@pve2:~# lsusb | grep -i arduino Bus 002 Device 009: ID 2341:8036 Arduino SA Leonardo (CDC ACM, HID) root@pve2:~# nut-scanner -U Scanning USB bus. [nutdev1] driver = "usbhid-ups" port = "auto" vendorid = "2341" productid = "8036" product = "Arduino Leonardo No CDC" serial = "HIDAJ" vendor = "Arduino LLC" bus = "002" root@pve2:~# grep "^[^#]" /etc/nut/ups.conf maxretry = 3 user = root [ups1] driver = usbhid-ups port = auto vendorid = 2341 productid = 8036 root@pve2:~# /usr/lib/nut/usbhid-ups -a ups1 -DDD -d1 Network UPS Tools - Generic HID driver 0.47 (2.8.0) USB communication driver (libusb 1.0) 0.43 0.000000 [D1] debug level is '3' 0.000578 [D2] Initializing an USB-connected UPS with library libusb-1.0.26 (API: 0x1000109) (NUT subdriver name='USB communication driver (libusb 1.0)' ver='0.43') 0.000590 [D1] upsdrv_initups (non-SHUT)... 0.006011 [D2] Checking device 1 of 7 (2341/8036) 0.008619 [D2] - VendorID: 2341 0.008635 [D2] - ProductID: 8036 0.008641 [D2] - Manufacturer: Arduino LLC 0.008647 [D2] - Product: Arduino Leonardo No CDC 0.008652 [D2] - Serial Number: HIDAJ 0.008657 [D2] - Bus: 002 0.008666 [D2] - Device: unknown 0.008678 [D2] - Device release number: 0100 0.008683 [D2] Trying to match device 0.008689 [D2] match_function_subdriver (non-SHUT mode): matching a device... 0.008697 [D3] match_function_regex: matching a device... 0.008764 [D2] Device matches 0.008774 [D2] Reading first configuration descriptor 0.008783 [D2] result: -5 (Entity not found) 0.008794 [D3] libusb_kernel_driver_active() returned 0 0.008803 [D2] failed to claim USB device: Entity not found 0.008813 [D1] failed to detach kernel driver from USB device: Invalid parameter 0.008824 [D2] failed to claim USB device: Entity not found 0.008835 [D1] failed to detach kernel driver from USB device: Invalid parameter 0.008845 [D2] failed to claim USB device: Entity not found 0.008856 [D1] failed to detach kernel driver from USB device: Invalid parameter 0.008866 [D2] failed to claim USB device: Entity not found 0.008875 [D1] failed to detach kernel driver from USB device: Invalid parameter 0.008883 Can't claim USB device [2341:8036]@2/0: Invalid parameter root@pve2:~# upsdrvctl start Network UPS Tools - UPS driver controller 2.8.0 Network UPS Tools - Generic HID driver 0.47 (2.8.0) USB communication driver (libusb 1.0) 0.43 Can't claim USB device [2341:8036]@2/0: Invalid parameter Driver failed to start (exit status=1)

abratchik

3 months ago

Hi @linkinpio, I'm not sure I can help, based on the logs you provided. I suspect it may be something related with the HID descriptor (if you did any changes to it). By the way, you dont need to disable the CDC if you take the latest NUT version.

yhiv

10 months ago

How to connect positive and negative levels?

petroleumchao

2 years ago

Great work! I have a question though. How does the Arduino board detect the capacity of the UPS? If I use a 12V lithium battery to power the PC directly, will the Arduino board still be able to accurately detect the battery level and status?

abratchik

a year ago

Thank you and sorry for long response. I'm not checking this board very often, unfortunately. Estimating remaining capacity of the lithium battery is usually done by measuring the voltage. The lover the voltage the less capacity is remaining, simple. The dependency between the voltage and the capacity is defined by the battery chemistry. You can google this for lithium batteries and implement your own capacity function of the voltage.

boriezz

2 years ago

Hi, I'm just wondering whether you think this could be implemented on other AVRs using V-USB?

abratchik

a year ago

Hi @boriezz. I think it could be done in theory since all the USB communication is low-speed, so it may work. I did not have a chance to play with V-USB but you may try to adapt it and share your results, it would be great.

logancarlile97

2 years ago

Sorry to ask but, could you explain what value the iA7 variable is supposed to hold. Specifically in this line: int iA7 = analogRead(A7); // TODO - this is for debug only. Replace with charge estimation Does it hold the estimated voltage of the battery? Thanks for the help!

megascott

2 years ago

Some ports on the MINI/Leonardo can be configured as Digital, Digital PWM out and Analog in. It looks like this is the case when he uses A7 in the code, which is the "Analog in" representation of the "Digital In" D6 pin, or in the Arduino IDE, just pin 6. It can be confusing, especially when the Fritzing diagram does not mention A7, only D6.

abratchik

2 years ago

This code was to simulate percentage of remaining battery charge. I just connected A7 pin to the potentiometer as on the schematics to simulate charge and discharge. In real application, the UPS USB should be isolated from the high-voltage circuits so the best approach would be to use another micro-controller (can be another Arduino board) controlling the UPS (inventor, battery charge etc) while communicating with the HID USB Arduino using serial connection via opto-couplers. One could extend this project, for example: https://www.homemade-circuits.com/arduino-pure-sine-wave-inverter-circuit/". The complete UPS solution, fully open source, would have 2 Arduinos, one for pure sine inverter and the other for USB interface, as suggested above.

chikiball

2 years ago

This is a wonderful project. While there is limited storage capacity on Pro Micro or Leonardo, porting this to ESP32 might be something to be considered. As more storage capacity is available in ESP32, more connectivity options are also possible like BLE or WiFi. More feature can be added to the Smart UPS such as display to small OLED/IPS screen, or BLE connectivity to an App on a smartphone. Please consider this.

janux

2 years ago

Great project, thanks for sharing. Connected to PC Works perfectly. I am trying to make it work connected to a Synology NAS (DS214 Play with DSM7) but in fact the NAS does not recognize Arduino Pro Micro (Sparkfun Pro Micro clone) as a USB NAS. Unfortunately I don't have the necessary skills to configure NUT on the NAS. Can you give me some indication on how to do it? I attach (link to my Dropbox) the assembly diagram on breadboard that if you want you can insert in your project. https://www.dropbox.com/s/c8hknckfmxj84bz/HID-UPS_BB.jpg?dl=0

janux

2 years ago

Thanks for the very quick reply abratchik, you are very kind and patient with a beginners like me! :) I know little about the Linux filesystem, I tried, by logging in from Windows PoweShell as root to manually edit the NUT .conf files located in /usr/syno/etc/ups, and then running 'upsd -c reload' or rebooting the system, but of course nothing has changed. Without first copying the new driver. I saw that the usbhid-ups driver on the NAS is located in usr/bin/ (167172 Mar 12 04:57 usbhid-ups). Where can I find the new driver? I found the modification of the Arduino configuration file very interesting to remove all device descriptors except HID proposed on GitHub by shadow578. I will follow the developments of the integration of Arduino support in NUT on GitHub. In the meantime, I'm trying to turn your great work into a home-made mini UPS dedicated to my NAS (when it will finally be able to recognize Arduino). This is just a first draft but since the Synology is powered by 12V I really like the idea of ​​avoiding double AC-DC/DC-AC conversion as with standard UPSs. https://www.dropbox.com/s/c4flq27xvwp337d/UPS-HID%20sch.jpg?dl=0 Thanks again, I appreciate your work and your suggestions. (Finally, sorry for my bad english but I used google translator).

abratchik

2 years ago

Hi janux, thanks for the diagram, will certainly add it! Regarding the Synology, it is not that simple unfortunately. NUT needs to be re-assembled from this branch - https://github.com/abratchik/nut to be compatible with Arduino UPS. Configuration will not help as NUT developers hard-coded VID/PID for all supported UPS models and also don't support composite USB devices, like Arduino. Disclaimer - I never tried NUT update on Synology, still in my to-do list. In theory, you need to access your Synology box via SSH, upload the usbhid-ups driver and replace the one you have in your system using CLI. If you are not very experienced with this then probably this is not a recommended way as you may brick your Synology box accidentally. I have submitted PR to NUT team so there is a chance it will be merged to the NUT release so Arduino support will come to Synology boxes naturally. Alternative option is to hack Arduino like it was done by shadow578 here - https://github.com/abratchik/HIDPowerDevice/issues/1#issuecomment-826086454. Probably this is is less risky approach.

abratchik

2 years ago

Hi janus, this is great effort, thanks for sharing. Added your diagram to the article and also referred you as a contributor, many thanks!

Anonymous user

2 years ago

This is a Great project, uploaded the code to a micro works straight out of the box on windows 10 nice!!, Sadly was hoping that my Synology NAS would detect it via USB as it does with APC UPS devices but it is not recognised, I guess it has something to do with PIDs any ideas?

Anonymous user

2 years ago

Most likely it is related with protocols Megatec & Voltronic.

abratchik

2 years ago

Never tested on Synology. Most likely it is related with PID/VID. I suspect they use NUT for managing UPS. If this is the case then supporting it may require a driver or hacking the NUT itself.

Anonymous user

2 years ago

Hello, i really like this project, i downloaded the library and tried to compile but the system reports compile errors to me: ``` "C:\\\\Program Files (x86)\\\\Arduino\\\\hardware\\\ ools\\\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-IC:\\\\Program Files (x86)\\\\Arduino\\\\hardware\\\\arduino\\\\avr\\\\cores\\\\arduino" "-IC:\\\\Program Files (x86)\\\\Arduino\\\\hardware\\\\arduino\\\\avr\\\\variants\\\\eightanaloginputs" "-IC:\\\\Program Files (x86)\\\\Arduino\\\\libraries\\\\HIDPowerDevice\\\\src" "C:\\\\Users\\\\Tomek\\\\AppData\\\\Local\\\\Temp\\\\arduino_build_279432\\\\sketch\\\\UPS.ino.cpp" -o "C:\\\\Users\\\\Tomek\\\\AppData\\\\Local\\\\Temp\\\\arduino_build_279432\\\\sketch\\\\UPS.ino.cpp.o" In file included from C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\examples\\UPS\\UPS.ino:1:0: C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:107:18: error: 'Serial_' has not been declared void setOutput(Serial_&); ^~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:99:27: error: 'IPRODUCT' was not declared in this scope const byte bProduct = IPRODUCT; ^~~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:99:27: note: suggested alternative: 'PRADC' const byte bProduct = IPRODUCT; ^~~~~~~~ PRADC C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:100:32: error: 'IMANUFACTURER' was not declared in this scope const byte bManufacturer = IMANUFACTURER; ^~~~~~~~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:100:32: note: suggested alternative: 'HID_PD_MANUFACTURER' const byte bManufacturer = IMANUFACTURER; ^~~~~~~~~~~~~ HID_PD_MANUFACTURER C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:101:26: error: 'ISERIAL' was not declared in this scope const byte bSerial = ISERIAL; ^~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:101:26: note: suggested alternative: 'SERIAL' const byte bSerial = ISERIAL; ^~~~~~~ SERIAL C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\examples\\UPS\\UPS.ino: In function 'void setup()': UPS:57:31: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' PowerDevice.setOutput(Serial); ^ In file included from C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino/Arduino.h:233:0, from C:\\Users\\Tomek\\AppData\\Local\\Temp\\arduino_build_279432\\sketch\\UPS.ino.cpp:1: C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino/HardwareSerial.h:135:5: note: after user-defined conversion: HardwareSerial::operator bool() operator bool() { return true; } ^~~~~~~~ In file included from C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\examples\\UPS\\UPS.ino:1:0: C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:107:8: note: initializing argument 1 of 'void HIDPowerDevice_::setOutput(int&)' void setOutput(Serial_&); ^~~~~~~~~ Użycie biblioteki HIDPowerDevice w wersji 1.0.0 z folderu: C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice exit status 1 cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' ``` (complete set of messages in the attachment). Could you please take a peek, because I'm a beginner and I can't solve it by myself.

abratchik

2 years ago

Hmm, very strange. Could you please share your board specs and also version of the arduino IDE? I'm using Mac or Unix for development so did not compile it on Windows ever.

Anonymous user

2 years ago

I am running into the same compiler issues.. First fatal error is line 57: PowerDevice.setOutput(Serial); cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' does not seem to a board or platform related issue.. perhaps it is something that has changed between whatever you compiled on and arduino 1.8.13? In any case.. Thoughts?

Anonymous user

2 years ago

Nevermind... I think I found the issue that pufik & I were both having.. I had selected pro for the target board.. not arduino micro.. Selecting a non native USB or non 32u4 board I think is what gives all those errors. My list of errors was nearly identical..

Anonymous user

2 years ago

Hi! Thanks for your work. It's exactly what I am searching to build my 12v UPS for NAS(s). With your latest status, dors it means that your fix for Synology is now included in your package and in thé official HID package? And did anybody try it on asustor or old dlink dns320l ? It could be a good Idea to get compatibility reports from users to know on which de systems your developpement has been tested. Thanks for all ! PS: as I understand, this HID is only possible on Leonardo. Is it possible on Uno too?

abratchik

2 years ago

Hi @papi_fr78, you are welcome, am glad you found this library useful. The fix for NUT has been merged and the latest release should support Arduino UPS, yes. Whether it is propagated to Sinology, or not yet - hard to say. It should be, sooner or later. Alternately you can try to patch NUT libs on your Sinology box by yourself. I did not do this experiment as I don't have a test NAS at hand. As a workaround, you can hack CDC and VID/PID on your arduino board, to make it advertise itself as a recognizable UPS on Interface 0. Regarding the compatibility, I tested only with Pro Micro and clones. Leonardo should work as well. Probably Uno will be working either.

Anonymous user

3 years ago

Please add support Digipark ATiny85 <code> In file included from D:\\Documents\\Arduino\\libraries\\HIDPowerDevice/HIDPowerDevice.h:29:0, from D:\\Documents\\Arduino\\libraries\\HIDPowerDevice\\examples\\UPS\\UPS.ino:1: D:\\Documents\\Arduino\\libraries\\HIDPowerDevice/HID/HID.h:26:26: fatal error: PluggableUSB.h: No such file or directory #include <PluggableUSB.h> ^ compilation terminated. exit status 1 Error compilation for board Digispark (Default - 16.5mhz). </code>

abratchik

2 years ago

This is not possible, unfortunately. The main idea of this project is to use the capabilities of Arduino Leonardo/Pro Micro, which can present themselves as a standard HID UPS device with this library. ATtiny85 doesn't have USB port so it doesn't really fit for the purpose.

lucm0

3 years ago

I am running into the same compiler issues.. First fatal error is line 57: PowerDevice.setOutput(Serial); cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' does not seem to a board or platform related issue.. perhaps it is something that has changed between whatever you compiled on and arduino 1.8.13? In any case.. Thoughts?

lucm0

2 years ago

Nevermind... I think I found the issue that pufik & I were both having.. I had selected pro for the target board.. not arduino micro.. Selecting a non native USB or non 32u4 board I think is what gives all those errors. My list of errors was nearly identical..

Anonymous user

3 years ago

Hello, i really like this project, i downloaded the library and tried to compile but the system reports compile errors to me: ``` "C:\\\\Program Files (x86)\\\\Arduino\\\\hardware\\\ ools\\\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-IC:\\\\Program Files (x86)\\\\Arduino\\\\hardware\\\\arduino\\\\avr\\\\cores\\\\arduino" "-IC:\\\\Program Files (x86)\\\\Arduino\\\\hardware\\\\arduino\\\\avr\\\\variants\\\\eightanaloginputs" "-IC:\\\\Program Files (x86)\\\\Arduino\\\\libraries\\\\HIDPowerDevice\\\\src" "C:\\\\Users\\\\Tomek\\\\AppData\\\\Local\\\\Temp\\\\arduino_build_279432\\\\sketch\\\\UPS.ino.cpp" -o "C:\\\\Users\\\\Tomek\\\\AppData\\\\Local\\\\Temp\\\\arduino_build_279432\\\\sketch\\\\UPS.ino.cpp.o" In file included from C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\examples\\UPS\\UPS.ino:1:0: C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:107:18: error: 'Serial_' has not been declared void setOutput(Serial_&); ^~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:99:27: error: 'IPRODUCT' was not declared in this scope const byte bProduct = IPRODUCT; ^~~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:99:27: note: suggested alternative: 'PRADC' const byte bProduct = IPRODUCT; ^~~~~~~~ PRADC C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:100:32: error: 'IMANUFACTURER' was not declared in this scope const byte bManufacturer = IMANUFACTURER; ^~~~~~~~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:100:32: note: suggested alternative: 'HID_PD_MANUFACTURER' const byte bManufacturer = IMANUFACTURER; ^~~~~~~~~~~~~ HID_PD_MANUFACTURER C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:101:26: error: 'ISERIAL' was not declared in this scope const byte bSerial = ISERIAL; ^~~~~~~ C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:101:26: note: suggested alternative: 'SERIAL' const byte bSerial = ISERIAL; ^~~~~~~ SERIAL C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\examples\\UPS\\UPS.ino: In function 'void setup()': UPS:57:31: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' PowerDevice.setOutput(Serial); ^ In file included from C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino/Arduino.h:233:0, from C:\\Users\\Tomek\\AppData\\Local\\Temp\\arduino_build_279432\\sketch\\UPS.ino.cpp:1: C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino/HardwareSerial.h:135:5: note: after user-defined conversion: HardwareSerial::operator bool() operator bool() { return true; } ^~~~~~~~ In file included from C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\examples\\UPS\\UPS.ino:1:0: C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice\\src/HIDPowerDevice.h:107:8: note: initializing argument 1 of 'void HIDPowerDevice_::setOutput(int&)' void setOutput(Serial_&); ^~~~~~~~~ Użycie biblioteki HIDPowerDevice w wersji 1.0.0 z folderu: C:\\Program Files (x86)\\Arduino\\libraries\\HIDPowerDevice exit status 1 cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' ``` (complete set of messages in the attachment). Could you please take a peek, because I'm a beginner and I can't solve it by myself.

abratchik

2 years ago

Hmm, very strange. Could you please share your board specs and also version of the arduino IDE? I'm using Mac or Unix for development so did not compile it on Windows ever.

janux

4 years ago

Great project, thanks for sharing. Connected to PC Works perfectly. I am trying to make it work connected to a Synology NAS (DS214 Play with DSM7) but in fact the NAS does not recognize Arduino Pro Micro (Sparkfun Pro Micro clone) as a USB NAS. Unfortunately I don't have the necessary skills to configure NUT on the NAS. Can you give me some indication on how to do it? I attach (link to my Dropbox) the assembly diagram on breadboard that if you want you can insert in your project. https://www.dropbox.com/s/c8hknckfmxj84bz/HID-UPS_BB.jpg?dl=0

abratchik

2 years ago

Hi janux, thanks for the diagram, will certainly add it! Regarding the Synology, it is not that simple unfortunately. NUT needs to be re-assembled from this branch - https://github.com/abratchik/nut to be compatible with Arduino UPS. Configuration will not help as NUT developers hard-coded VID/PID for all supported UPS models and also don't support composite USB devices, like Arduino. Disclaimer - I never tried NUT update on Synology, still in my to-do list. In theory, you need to access your Synology box via SSH, upload the usbhid-ups driver and replace the one you have in your system using CLI. If you are not very experienced with this then probably this is not a recommended way as you may brick your Synology box accidentally. I have submitted PR to NUT team so there is a chance it will be merged to the NUT release so Arduino support will come to Synology boxes naturally. Alternative option is to hack Arduino like it was done by shadow578 here - https://github.com/abratchik/HIDPowerDevice/issues/1#issuecomment-826086454. Probably this is is less risky approach.

abratchik

2 years ago

Hi janus, this is great effort, thanks for sharing. Added your diagram to the article and also referred you as a contributor, many thanks!

janux

2 years ago

Thanks for the very quick reply abratchik, you are very kind and patient with a beginners like me! :) I know little about the Linux filesystem, I tried, by logging in from Windows PoweShell as root to manually edit the NUT .conf files located in /usr/syno/etc/ups, and then running 'upsd -c reload' or rebooting the system, but of course nothing has changed. Without first copying the new driver. I saw that the usbhid-ups driver on the NAS is located in usr/bin/ (167172 Mar 12 04:57 usbhid-ups). Where can I find the new driver? I found the modification of the Arduino configuration file very interesting to remove all device descriptors except HID proposed on GitHub by shadow578. I will follow the developments of the integration of Arduino support in NUT on GitHub. In the meantime, I'm trying to turn your great work into a home-made mini UPS dedicated to my NAS (when it will finally be able to recognize Arduino). This is just a first draft but since the Synology is powered by 12V I really like the idea of ​​avoiding double AC-DC/DC-AC conversion as with standard UPSs. https://www.dropbox.com/s/c4flq27xvwp337d/UPS-HID%20sch.jpg?dl=0 Thanks again, I appreciate your work and your suggestions. (Finally, sorry for my bad english but I used google translator).

Anonymous user

4 years ago

This is a Great project, uploaded the code to a micro works straight out of the box on windows 10 nice!!, Sadly was hoping that my Synology NAS would detect it via USB as it does with APC UPS devices but it is not recognised, I guess it has something to do with PIDs any ideas?

Anonymous user

2 years ago

Most likely it is related with protocols Megatec & Voltronic.

abratchik

2 years ago

Never tested on Synology. Most likely it is related with PID/VID. I suspect they use NUT for managing UPS. If this is the case then supporting it may require a driver or hacking the NUT itself.

logancarlile97

4 years ago

Sorry to ask but, could you explain what value the iA7 variable is supposed to hold. Specifically in this line: int iA7 = analogRead(A7); // TODO - this is for debug only. Replace with charge estimation Does it hold the estimated voltage of the battery? Thanks for the help!

abratchik

2 years ago

This code was to simulate percentage of remaining battery charge. I just connected A7 pin to the potentiometer as on the schematics to simulate charge and discharge. In real application, the UPS USB should be isolated from the high-voltage circuits so the best approach would be to use another micro-controller (can be another Arduino board) controlling the UPS (inventor, battery charge etc) while communicating with the HID USB Arduino using serial connection via opto-couplers. One could extend this project, for example: https://www.homemade-circuits.com/arduino-pure-sine-wave-inverter-circuit/". The complete UPS solution, fully open source, would have 2 Arduinos, one for pure sine inverter and the other for USB interface, as suggested above.

Anonymous user

2 years ago

Some ports on the MINI/Leonardo can be configured as Digital, Digital PWM out and Analog in. It looks like this is the case when he uses A7 in the code, which is the "Analog in" representation of the "Digital In" D6 pin, or in the Arduino IDE, just pin 6. It can be confusing, especially when the Fritzing diagram does not mention A7, only D6.