HSC pressure sensors via SPI Arduino

4 views (last 30 days)
Hi! Does anyone know the robust way of connecting Honeywell HSC pressure sensors via SPI and Arduino board?
Suggested here SPI interface supports only Aardvark and NI connections:
The idea is quite simple: to drop CS pin to 'low' and read just four (4) bytes of data from MISO (there's no MOSI at all) and then close connection.
Cheers

Accepted Answer

Arun Kumar
Arun Kumar on 11 Jun 2019
Hi Viacheslav,
What I understood from your question is that you want to read data from a SPI device using arduino.
To do this, you can use MATLAB Support package for Arduino Hardware.
Here is the link to download that:
And here is the link to the documentation of SPI communication on Arduino using MATLAB:
Hope this helps.
Cheers
  2 Comments
Viacheslav Sedunin
Viacheslav Sedunin on 11 Jun 2019
Edited: Viacheslav Sedunin on 11 Jun 2019
Dear Arun, Thanks for your reply, truly appreciate. I do have this package and have seen the example. The problem is that HSC transfers data in four bytes, and the bits of interest are spread all around. E.g. To know pressure I need bits 5-8 in the first byte AND all 8 bits of the second byte. For temperature its 8 + 3 bits of the fourth byte. I cannot read 4 bytes separately at the first place. Then I think converting them could be doable. Here is the datasheet:
Cheers
Arun Kumar
Arun Kumar on 12 Jun 2019
Hi Viacheslav,
Reading 4 bytes should not be any issue with arduino.
Refer this page for details:
You can read 4 bytes like this:
a = arduino;
dev = device(a,'SPIChipSelectPin','D10');
dataOut = writeRead(dev,zeros(1,4));

Sign in to comment.

More Answers (2)

Viacheslav Sedunin
Viacheslav Sedunin on 18 Jun 2019
Dear all,
Thanks to Arun's help and thanks to my colleague here is the code for 3 HCS sensors. Feel free to comment on that and use it as you like. Would appreciate any improvments and comments as I'm totally new to Matlab.
% This is a cleaned-up version of operation with one 3 HSC sensors
% HSCDRRD160MDSA5 SPI based, +/-160mbar range, DIP mounted
clear all
a = arduino;
% when I added('COM3','Uno','Libraries','SPI') - it stopped working adequately as
% these options are for NI libraries
HSC(1) = device(a,'SPIChipSelectPin','D9','BitRate',115200);
HSC(2) = device(a,'SPIChipSelectPin','D8','BitRate',115200);
HSC(3) = device(a,'SPIChipSelectPin','D7','BitRate',115200);
%
%for more robust data transfer Bitrate can be reduced, but make sure you
%change it in the device manager for your COM port device
%
%
% Defining pressure range
%
pLow = [-160, -160, -160];
pHigh = [160, 160, 160];
Range = pHigh - pLow;
%Done with initializing
%%
for i = 1:3
dataOut = writeRead(HSC(i),zeros(1,4));
p1 = bitget(dataOut(1),6:-1:1);
p2 = bitget(dataOut(2),8:-1:1);
t1 = bitget(dataOut(3),8:-1:1);
t2 = bitget(dataOut(4),8:-1:6);
pDig = [p1 p2];
tDig = [t1 t2];
pCount = sum(fliplr(2.^(0:13)).*pDig);
tCount = sum(fliplr(2.^(0:10)).*tDig);
t(i) = (tCount*200/2047)-50
p(i) = (pCount-1638.4)*Range(i)/(14745.6-1638.4)+pLow(i)
end

Viacheslav Sedunin
Viacheslav Sedunin on 14 Jun 2019
Dear Arun,
I did similar stuff - it works reasonably well, however sometimes it keeps getting random numbers. However, the same setup with Arduino IDE code does provide consistent results thruoghout testing.
E.g. normally it has an array ( 31 249 92 239) with uncertainty +/- 5 which is perfectly fine.
But sometimes it could give me (31 31 252 249) or ( 27 255 251 239) which is super far away.
Aso, could you please help me in making one number out of first 6 bits of byte 1 and 8 bits of byte 2? Not sum them, but make 14 digits binary number.
I do:
a = arduino('COM3','Uno','Libraries','SPI');
HSC1 = device(a,'SPIChipSelectPin','D9','BitRate',9600);
%%
dataOut = writeRead(HSC1,zeros(1,4))
  1 Comment
Arun Kumar
Arun Kumar on 14 Jun 2019
Hi Viacheslav,
The random values could be because of wrong clock speed. Can you check the SPI clock speed supported by your sensor and the SPI clock configured in matlab.
For decoding values from two bytes, you can use the code below:
msb = bitshift(bitand(byte1,bin2dec('111111')),8); %Extracting only 6 bits and shifting it by 8
lsb = byte2;
out = bitor(msb,lsb);

Sign in to comment.

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!