danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Mon Jan 05, 2015 1:06 pm

I just forgot about one Xbee possibility.

You could use the io passing method with the xbee. Even simpler. You just have to detect the i/o change.

http://www.instructables.com/id/Remote- ... e-Passing/

ve7mkf
Posts: 2
Joined: Fri Feb 06, 2015 4:12 am
Location: Surrey, BC, Canada

Re: Multi-function RS-485 remote sensor

Fri Feb 06, 2015 4:27 am

Hello Daniel,

Thank you for this project It is exactly what I was looking for! I am working on some remote data acquisition for home monitoring and thought it would be good to learn about both RS-485 and Modbus. You have both in your project :D

I do have a couple of questions:
1) I have been breadboarding up your test circuits and need some clarification. The circuit diagram for your Modbus Converter for the Raspberry-Pi (dated 18-Nov-2013) shows a 1k resistor from LTC485 pin 6 (A) to ground and 1k resistor from pin 7 (B) to +5V, but the photo of your test circuit on the breadboard has it the other way around (1k from A to +5V, 1K from B to ground). Just wondering which is correct?

2) I have your PIC Multi-IO-10 programmed and working on breadboard (direct to Ras-Pi UART). The config and test programs work fine. I am a little confused about modbus memory and function calls to get data. I have looked through the course code some. Is it possible for you to publish some sort of Modbus memory map that shows what data is stored in which memory location?

Thanks Again,

Mike

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Fri Feb 06, 2015 2:56 pm

I create this spreadsheet maybe it will help you

https://docs.google.com/spreadsheets/d/ ... sp=sharing

For the RS-485 the pull-up resistor (source mode) is on the A side, pin 6.
The pull-down , sink mode is on the B side , pin 7.

Daniel

ve7mkf
Posts: 2
Joined: Fri Feb 06, 2015 4:12 am
Location: Surrey, BC, Canada

Re: Multi-function RS-485 remote sensor

Sat Feb 07, 2015 4:19 am

Thanks Daniel, the spreadsheet explains things very well. Thanks also for the clarification on the pull-up and pull-down resistors.

Mike

ajwitmer-bosley0
Posts: 1
Joined: Wed Feb 11, 2015 8:36 pm

Re: Multi-function RS-485 remote sensor

Wed Feb 11, 2015 8:40 pm

Dan,
you seem to know what you are doing. I hope this will be worth your time. I am attempting to read and log temperature readings with the pi. I need a sampling rate of 100Hz or more and a capability of reading temperature differences of air to the order of <1.0C. Any sensor recommendations?

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Thu Feb 12, 2015 12:03 am

You will have to look at some I.R. sensor!
Direct thermal sensor won't be fast enough!
Something like Melesix MLX90615.

I didn't have any I2C on my multi I/O code.
It is possible. IO1 & IO2 could be SDA and SCL.
But you will have to make your own code or directly use the Raspberry PI to read it.

Daniel

sorghiro
Posts: 3
Joined: Wed Feb 25, 2015 5:47 pm
Location: Poggio Mirteto, Italy, UE

Re: Multi-function RS-485 remote sensor

Sun Jul 26, 2015 3:50 pm

Hi Daniel,
I am trying to work on some remote data acquisition for home monitoring and, as well as mike (ve7mkf) wrote, I found that your project is exactly what I was looking for.

I am a beginner about ModBus, so I decided to develope the WaterDetect project because it seems your simplest project to study.

My main hardware is Raspberry Pi 2 Model B, SN75176AP and PIC12F1840.

I followed step by step your "DIY a water detection from a small cpu" to have a working project to begin learning.

In step 2 I did not find the file intelhex-1.5.zip to which you have referred, but at https://launchpad.net/intelhex/+download

Apart from that, all went well until I tried to change the slave address (Step 5).
In Step 5, when I run "./SlaveAddress.py 127 1" the program changes properly the slave address, but returns "Checksum error in rtu mode" instead of "Wrong return slave address". The returned message is shown in attach.

I think that it does not depend on bad contact (random error) because the message is always the same every time I run the python program.
Even rule out an error in the code because you test the code many times.

I read that it could be due to local echo or bad settings.
What do you think about it? Have you already met a similar error?
Can you help me?

Thanks again,
Francesco
Attachments
Checksum_error.gif
Checksum_error.gif (61.86 KiB) Viewed 5661 times

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Sun Jul 26, 2015 10:57 pm

It is a bug that I never corrected.

When you change the Address the module reply with the new address instead of the old one and minimal modbus return with an error.

The new address is set!

Just use CheckModbus.py with the new address and you will see that it is working.

sorghiro
Posts: 3
Joined: Wed Feb 25, 2015 5:47 pm
Location: Poggio Mirteto, Italy, UE

Re: Multi-function RS-485 remote sensor

Mon Jul 27, 2015 1:29 pm

Sorry about the question but I thought the "Checksum error in rtu mode" and "Wrong return slave address" were due to different causes.

Yes, CheckModbus.py works.

Thank you for your reply,
Francesco

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Mon Jul 27, 2015 1:55 pm

To fix the bug simply change Setting.SlaveAddress to ModbusSlave in the function SendPresetFrame(), This is line 627.

Recompile and burn the code to the cpu .

mkohns
Posts: 1
Joined: Fri Jul 31, 2015 7:47 am

Re: Multi-function RS-485 remote sensor

Fri Jul 31, 2015 7:52 am

Hi Daniel,

very nice project! My compliments.

I have one question: Before you used the USB2RS485 Converter from DX - your schematics (https://docs.google.com/document/d/1lXs ... VQfOA/edit) show an self made PIC based RS485 Converter which is connected to the UART from the RPI. In your GitHub and in the above documentation I can not find the hex or source files for this PIC based converter. Can you help me out here?

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Fri Jul 31, 2015 3:39 pm

The hex code for the RS-485 switches is with another project.

https://github.com/danjperron/NoContactWaterDetect.git

I do have a manual for that project also
https://docs.google.com/document/d/1YN4 ... sp=sharing

sorghiro
Posts: 3
Joined: Wed Feb 25, 2015 5:47 pm
Location: Poggio Mirteto, Italy, UE

Re: Multi-function RS-485 remote sensor

Mon Aug 03, 2015 11:11 am

Hi Daniel,
I did what you suggested to fix the "Wrong return slave address" and it works.

However, your suggestions do not solve "Checksum error in rtu mode".
To do this you need to change the code in function SendPresetFrame() from line 629 to line 642 to cut off byte count data (buffer[2]= 2; at line 629), because Payload data from slave (Response) of the code 6 function is only Register address [2 Bytes] and Value [2 Bytes] (see Modbus implementation details at https://minimalmodbus.readthedocs.org/e ... tails.html).

I hope you will agree when I say that the right function SendPresetFrame() should be:

void SendPresetFrame(void)
{
unsigned loop;
unsigned char buffer[8];
unsigned short CRC;

buffer[0] = ModbusSlave; //Setting.SlaveAddress;
buffer[1] = ModbusFunction;
buffer[2] = ModbusAddress >> 8;
buffer[3] = ModbusAddress & 0xff;

buffer[4] = ModbusData >> 8;
buffer[5] = ModbusData & 0xff;

CRC = CRC16(buffer,6);
buffer[6] = CRC >> 8;
buffer[7] = CRC & 0xff;

for(loop=0;loop<8;loop++)
putch(buffer[loop]);

ModbusTransmitFlag=1;

}

I hope I was helpful.
Regards
Francesco

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Mon Aug 03, 2015 11:50 am

Hi sorghiro,

You are correct . I just look at my code and figure out what is needed. I didn't check it since for me it was a minor error.

I'm on vacation ! I will do the correct verification when I retrun.


At least I hope that my little code is good enough for you.


I have two problems with my code.

1- I want it to be easy to compile for everyone and this imply to use some assembly to correct for the none optimize free version and to be able to shrink the code. It is not a problem in reality but make it more difficult to understand.

2- The DHT22 and the DS18B20 sensor are on interrupt capture but if you are using the counter mode they could behave erractically if your counter pulse are too high.


Depending on the rs-485 adapter you have,you need to add some bias resistors, This way when no one transmit the RCV pin is ttl high.

The schematic you got with the rs-485 switch contains the bias resistors.

lwiki
Posts: 4
Joined: Sun Oct 08, 2017 7:14 pm

Re: Multi-function RS-485 remote sensor

Sun Oct 08, 2017 7:19 pm

Hi Daniel,

thank you very much for sharing of your PIC_MULTI_10_IO project. I’ve set it up and is working really nice.
I’d like to ask you couple of question about your project.

1) I found out the DHT 22 is quite unstable in the reading it. I get about 2% of successful readings and the rest just fail. Is this known issue to you, do you have some idea how to get successful reading from this sensor. I used also AM2303 and this is working very stable.

2) I’d like to extend your project about measuring of weight. I’m going to use the Single point load cell H30A:

https://www.bosche.eu/en/scale-componen ... gI94_D_BwE

I suppose to get it working I’ll need the HX711 ADC for Weigh Scalese:

https://cdn.sparkfun.com/datasheets/Sen ... nglish.pdf

Could you please give me a couple of hints if it is possible to extend the PIC configuration about this kind of input? And how would you proceed?

Thank you very much for your feedback

Regards

Peter

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Sun Oct 08, 2017 7:54 pm

I dont remember having problem with the DHT22. I will check my current settings.


Could you tell me what is your other IO pins configuration.

For the weight measurement you could simply add an OPAM to increase the range. I wasn't able to get the electronic schematic but looks like a normal bridge load cell.

Don't forget that you could set some IO into ADC with 10 bits resolution.

Daniel

lwiki
Posts: 4
Joined: Sun Oct 08, 2017 7:14 pm

Re: Multi-function RS-485 remote sensor

Mon Oct 09, 2017 3:51 am

Hi Daniel,

thank you for your input.

1) from the previous message with the DHT22 problem I meant the AOSONG-AM2302 which is the most selling DHT22 here in Europe. The AM2303 I had to order from China. In my use case I’ve connected for each unit/pic 2xDHT22 and 2xDS18B20. I was testing 3 different AM2302 and for all of them I get the same problem. There may be some difference between AM2302 and AM2303.

2) Yes it is normal bridge load cell. Is it possible to set some IO in ADC in the current version or do I need to do some modifications to main.c?


Regards

Peter

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Mon Oct 09, 2017 12:33 pm

I found a bug in my code for the DHT22. Looks like that the reset needed for the sensor is not working. (missing the code). I will need to change some C functions in assembly to free space to correct the code.

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Mon Oct 09, 2017 1:31 pm

Ok Bug Fix!

in DHT22.c I was missing "Timerms=0". The reset was never done

Code: Select all

void DHT22CycleIdle(void)
{
 unsigned short _temp;
 unsigned char _ctemp;

if(Timerms > 1000)  // more than 1000ms
 {
   // ok Half second pass 
   // time to start pulse
    Timerms=0;
in the function DHT22CycleStart I need to go into wait mode after the reset is done.

Code: Select all

void DHT22CycleStart(void)
{
    unsigned char _ctemp= IOMASK[CurrentIOPin];
    unsigned char _ntemp= ~_ctemp;
  // wait until Timerms got at least 2ms (2 counts).

CurrentIOStatus=IO_STATUS_UNKNOWN;


    if(Timerms >3)
  {
    // release for
CurrentIOCycle= IO_CYCLE_WAIT;
I will push my github tonight.

For the ADC there is nothing to do. Find out the maximum weight for your blance and figure out the maximum Voltage in mv and then add an OPAM in diffrential mode to convert the load cell output to the voltage you want to read. The build in ADC could be set with 4 differents references. (VDD, 1.024V, 2.048V and 4.096V). Just use configPIC and select it

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Mon Oct 09, 2017 9:16 pm

OK I push a new version with a fix for DHT11/22.

I also modified my code to remove all the warnings.

https://github.com/danjperron/PIC_MULTI_10_IO

lwiki
Posts: 4
Joined: Sun Oct 08, 2017 7:14 pm

Re: Multi-function RS-485 remote sensor

Wed Oct 11, 2017 3:58 am

Hi Daniel,

I see the bug and thank you very much for the fix.

For the ADC, would you go for INA125P amplifier?
Something like this :
https://cdn.instructables.com/FNY/02KS/ ... MEDIUM.jpg

Or you see better option?

Regards

Peter

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Wed Oct 11, 2017 11:12 am

The 1NA125P will do very well but it is quite expensive. Maybe too much precise for 10 bits resolution.

A LM358 could do also. google LM358 Bridge.

First I will check if 10 bits resolution is ok. Is it enough. Do you need more than 1024 step?

lwiki
Posts: 4
Joined: Sun Oct 08, 2017 7:14 pm

Re: Multi-function RS-485 remote sensor

Wed Oct 11, 2017 8:40 pm

Hi Daniel,

yes 1024 steps are enough.
The voltage for maximum weight from the load cell is 15 mV.
I suppose I need the “Figure 42. High Input Z, DC Differential Amplifier” from the datasheet of LM358.
If I use from the PIC the build in ADC reference: 1.024V, then the output from LM358 needs to be maximum 1.024V for maximal weight, right?

Thank you
Regards
Peter

danjperron
Posts: 3406
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multi-function RS-485 remote sensor

Thu Oct 12, 2017 7:05 pm

If I use from the PIC the build in ADC reference: 1.024V, then the output from LM358 needs to be maximum 1.024V for maximal weight, right?
The analog input will support voltage up to VCC.
But this is correct . If you set the reference to 1.024V then 1.023V will be a digital value conversion of 1023.

natashasmg
Posts: 1
Joined: Tue Jan 16, 2018 3:33 pm

Re: Multi-function RS-485 remote sensor

Thu Jul 12, 2018 7:04 pm

danjperron wrote:
Sat Jun 14, 2014 12:56 am
I just received my orders with three different type of RS-485 adapters.

They all works except they are connected differently.


The first one is the USB to 485 adapter. Really simple to implement and no handshake needed since it is done automatically.

The adapter , when it is connected, will simply add a serial device into the Raspberry. (/dev/ttyUSB0)

Image

The two others devices are shields, 5V and 3.3V adapter which you connect using the GPIO RX/TX pins. (/dev/ttyAMA0)




On both devices you need to take care of the received/transmit handshake. For this reason I use my rs485 switcher program with the PIC12F1840 cpu. This is a very simple solution to deal with the handshake. I don't have to implement it into the Rpi.

On the 5V adapter, you need to take care of the RO signal by reducing the maximum current it delivers to the gpio. A simple 4k7 resistor in serie will limit the current to prevent the 3.3V to increase.

Image

The 3.3V adapter is directly connected , with my cpu handshake handler, to the GPIO.
But we need to get 3.3V not from the RPI since there is only 30ma available.

Image

My cpu code for the Receive/transmit handshake is in the github .

https://github.com/danjperron/NoContactWaterDetect.git

I like the USB!
It is simple and very clean to install, except no hole to mount it.

Daniel
Hello Daniel... I have a TTL to RS485 converter like you, but I have many problems with that.. I am using this to my university project
I need help :( I am trying all .. I have used all the option that I have read on the web.
I connected GPIO 17 with (RE and DE) and DI - GPIO TX and RO- GPIO RX to use the half duplex communication
my code is :
import RPi.GPIO as GPIO
import minimalmodbus
import serial
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)

print "Transmiting Data"
GPIO.output(17,GPIO.HIGH)
ser = serial.Serial('/dev/ttyAMA0', baudrate = 4800, timeout = 1.0)
print ser
ser.write(':010310010001EA\r\n')
GPIO.output(17,GPIO.LOW)
print "Receiving.."
print ser.read(1000)


instrument = minimalmodbus.Instrument('/dev/ttyAMA0',02,minimalmodbus.MODE_ASCII)
instrument.serial.baudrate = 4800
instrument.serial.bytesize = 8
instrument.debug = True
#instrument.handle_local_echo =True
print "Receiving.."
GPIO.output(17,GPIO.LOW)
#print minimalmodbus._getDiagnosticString()
print instrument.read_string(1,16)

GPIO.output(17,GPIO.HIGH)


but this is the result:
IOError: No communication with the instrument (no answer)
WhatsApp Image 2018-07-12 at 3.01.00 PM.jpeg
WhatsApp Image 2018-07-12 at 3.01.00 PM.jpeg (65.12 KiB) Viewed 1976 times
Thank u ! :!: :!:

Return to “Interfacing (DSI, CSI, I2C, etc.)”