Main Site Documentation

Inclination Sensor - ANALOG (4..20mA) or MODBUS RTU RS-485 input?


Dear GHI Community,

I would like to have your opinion and help. I want to use an inclination sensor for my project. I am using the FEZ Spider main-board and want to make sure that the sensor I want to buy will be compatible with this main-board, I want to make sure that I am going to be able to read the sensor’s outputs! I took some time to study the available information on the forum here and on other websites. Here, I just want to ask for your opinion, approval.

The manufacturer ( offers sensors with two types of output:
[ul]Analog output: 4-20 mA (datasheet:[/ul]
[ul]Modbus RTU RS-485 (datasheet:[/ul]

Which output signal type should I choose? What do you think?

Let me quickly describe my understanding of the two possibilities.

I know that the FEZ Spider mainboard has analog inputs that can read a voltage value between 0V DC and 3.3V DC. So, If I choose the 4-20 mA current loop output type of the sensor then I would have to convert this current to voltage, so that the Spider’s analog input can read it. What I think is that I would have to use a 165 Ohm resistor (0.1%, ±15ppm/°C, 250mW) so that the voltage drop across the resistor would be Uhigh = IhighR = (20 mA)(165 Ohm) = 3.3V! The voltage drop when the current is 4 mA would be Ulow = IlowR = (4 mA)(165 Ohm) = 0.66V! So, whenever I read a value of 0.66V then I know that I have 0° inclination angle and whenever I read 3.3V I know that the inclination is equal to 360°. Am I right? Is it really so easy, just use an external resistor and that’s it? Is the measurement going to be precise enough? I really do not need a 0.01° accuracy but 1° is desired, even 2° would be OK. Am I going to achieve this accuracy? My understanding is that I will have a voltage range between 0.66V and 3.3V which makes 2.64V for the measurements. According to a formula presented here ( I get a resolution of about 0.44° with the 10-bit ADC of the FEZ Spider. Am I right? Can I be sure that I will have an accuracy of 0.5° or let’s say less then 1°? If not, could you please recommend me a better ADC and tell me how to wire it to the FEZ spider? I used the following document that helped me understand the 4-20 mA current loop:

The second option (Modbus RTU RS-485) looks a little bit more difficult/complicated to implement. First of all, the FEZ Spider mainboard does not have any port that can directly read RS-485 signals. So, as I already read in a few topics, I would have to use an RS-232 / RS-485 converter and then use the RS-232 module from GHI. But then I would also have to use some software to read the signals and convert them to inclination angles. One of the possibilities (as discussed in this topic: I see here is to use the following library (from Mario Vernari):

If I use the library from Mario and a 10€ RS-232 / RS-485 converter, am I going to be able to read the signals and calculate the inclination angle? Another thing I want to ask you if it would be possible to use a RS-485 / USB converter (ängerungskabel-Einsetzbar/dp/B00823K7F0/ref=sr_1_8?ie=UTF8&qid=1367998497&sr=8-8&keywords=rs485+rs232+converter) and then use the USB module from GHI to connect it to the FEZ Spider mainboard. Would I still need some external library then?

After my description of the above options, which one should I opt for? What do you think? Should I choose the 4-20 mA analog signal or the Modbus RTU RS-485 digital signal?

If I have to be honest, if the only thing I need for the 4-20 mA analog signal type is a 165 Ohm resistor, then I would choose this option.

Looking forward to receiving your tips and hints for this issue! THANK YOU!


What resolution do you need?

This has an impact on the method you use. The 4-20mA with 165 ohm will give you a span of 0.66 to 3.3V.

I would choose a lower value to keep the upper 20mA below 3.3V as it’s a little close to the ADC range input.

With your 165 omhs you will have ±1.32 volt swing, taking into consideration the zero offset.

You need to work out the angular resolution with this. I assume you will use the built in ADC? What resolution?


Well, as I already mentioned, I need a resolution of 1° or better. The thing is that I would prefer to use the built in ADC which has 10-bit resolution. If using an external ADC with higher resolution isn’t very complicated then I might consider using one. Could you tell me how it would work with an external ADC, could you suggest a product?


If you don’t need fast sampling, the MCP3428 is a four channel device with 15 samples per second at 16 bit.

As you only need 1 deg resolution, you might find that the 10 bit ADC should be ok. Work out the resolution from that and see. Also account for ADC noise.

By the way, a 150 ohm resistor might be more suitable and keep within the ADC range.


Why would a 150 Ohm resistor be more suitable?


The output would swing from 0.6 to 3.0 volts with 150 ohms.

Your 165 puts the 20mA input at 3.3V and this is very close the max input of the ADC. I have noticed that some 4-20mA sensors can output a little more than the 20mA depending on their type and use. Having the 3.0V as your max gives you a little headroom to read this over range if it exists.

It’s just my personal opinion that’s all based on my own experience of 4-20mA.


Dave, thank you for your tips, I will consider trying a 150 Ohm resistor. What do you think about the other option - the Modbus RTU RS-485? Does it offer some advantages? Could I use it, the way I described in the very first post, with the FEZ Spider?


RS485 - you have two options. First, you could try as you said, with an RS232 module and a RS232/RS485 module, but as you can see there’s a lot involved. Alternatively you could look at a max483/max485 or any other RS422/485 chip on a module and connect it up yourself. Perhaps something like this ? Personally I’d want to have an in-one solution rather than a multi-hop, even if I had to use a breakout to go to my desired end-connection type


Brett, I also saw this converter and found it interesting. In the description it says that it is 5V, but on the board itself is written 3-5V. So, would it be OK to use it with the FEZ Spider? And if I use this, would I need the external MODBUS RTU library I already mentioned, or I can just use the normal serial port of the Spider? To which port would I wire the module and how exactly, could you provide some detailed help? It would be great.


@ Teodor17 - how about just using an accelerometer?


Justin, an accelerometer could be an option, I even have one. But its accuracy is not good and I want to use the sensor 24/365 outside which means I would have to buy an enclosure and so on. The idea is to use a sensor from a manufacturer and implement it. After all, my understanding is that, for example RS-485 is perhaps 35 years old and it is still around because of its simplicity. And it is so strange that I do not really know if I could use it with FEZ Spider. Nobody answers this directly or gives some hints.

If I use this RS-485 Breakout ( would I need to use the Modbus RTU RS-485 Library from Mario ( or I could use just the normal serial port functions offered from GHI and NETMF? Can someone help here?


If you use a Modbus library you will have no code to write. Of course, if you are only looking for basic communications you can just code it directly. Modbus is just a simple protocol but using a library, if you can get one, speeds up the process.

As for RS485 communications, you need to handle the TX/RX swithing if the bus driver you are using does not handle this for you. Maxim have an automatic device that is 8 pin but it is 5V only so you either need a level shifter or 5V tolerant IO on your processor.

I would go with the 4-20mA if resolution is not an issue.

RS485 if you have experience of using Modbus.