# ADC Value in NodeRed

**URL:** https://discourse.nodered.org/t/adc-value-in-nodered/67363
**Category:** General
**Created:** [5 September 2022 20:46 UTC](https://discourse.nodered.org/t/adc-value-in-nodered/67363 "2022-09-05T20:46:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)
#### Post date: [5 September 2022 20:46 UTC](https://discourse.nodered.org/t/adc-value-in-nodered/67363/1 "2022-09-05T20:46:58Z")

</div>

Hello

I have a python program in my raspberry.

```auto
from periphery import I2C
def get_adc_value():
	# Open i2c-1 controller
	i2c = I2C("/dev/i2c-1")

	msgs = [I2C.Message([0x61]), I2C.Message([0x00,0x00], read=True)]
	i2c.transfer(0x36, msgs)
	adc_value = (msgs[1].data[0] & 0x0F) <<8 | (msgs[1].data[1])

	# ATTENTION le 4.93 est la tension de ref mesurée à la main
	# pas utile en mode ratiometrique
	adc_value_volt=(adc_value*4.93/4096)
	print("ADC VALUE P4.2: 0x{:04x} , {:0.2f}V".format(adc_value,adc_value_volt))

	msgs = [I2C.Message([0x63]), I2C.Message([0x00,0x00], read=True)]
	i2c.transfer(0x36, msgs)
	adc_value = (msgs[1].data[0] & 0x0F) <<8 | (msgs[1].data[1])

	adc_value_volt=(adc_value*4.93/4096)
	print("ADC VALUE P6.2: 0x{:04x} , {:0.2f}V".format(adc_value,adc_value_volt))

	i2c.close()

```

I want to integrate this function in my node red in order to have only one point of debug.  
Can you tell me how to do it?

Thank You

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [5 September 2022 21:39 UTC](https://discourse.nodered.org/t/adc-value-in-nodered/67363/2 "2022-09-05T21:39:57Z")

</div>

Well you could call it from an exec node. python -u path-to/yourfile.py or did you want to implement it 100% in Node-RED using the i2c node ?

---

<div class="post-metadata">

### Author: ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)
#### Post date: [5 September 2022 21:54 UTC](https://discourse.nodered.org/t/adc-value-in-nodered/67363/3 "2022-09-05T21:54:03Z")

</div>

I will integrate 100% in node red because the resut of msg does anaylsed in node red

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [5 September 2022 22:46 UTC](https://discourse.nodered.org/t/adc-value-in-nodered/67363/4 "2022-09-05T22:46:20Z")

</div>

If you look in the flows section and search for ADC you will find a number of nodes designed to read from ADC devices attached to a RPi.

eg [node-red-contrib-iiot-rpi-ads1115 (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-iiot-rpi-ads1115)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [4 November 2022 22:46 UTC](https://discourse.nodered.org/t/adc-value-in-nodered/67363/5 "2022-11-04T22:46:47Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
