フィルターのクリア

ADS1115 With Simulink / Raspberry Pi (ADS1x15 Block) - Multi-Channel Read Issue?

6 ビュー (過去 30 日間)
Kyle
Kyle 2024 年 7 月 23 日
コメント済み: Kyle 2024 年 8 月 9 日
Hi there,
I have a simulink model that is being deployed on a raspberry pi 4 model B. I am trying to use the ADS1x15 block from the "Simulink Support for Raspberry Pi Hardware" package. My issue is that I am not able to read from more than one channel at once. If I create two instances of the block, and select the appropriate channels, they output the same thing. Is this a known issue, or have I not configured the block or model properly? Or is there some workaround for this?
I saw a previous question posted on the Matlab Answers forum and the only answers seem to keep pointing at this one 8 year old video on youtube that creates an S-Function instead of using the dedicated library blocks (the video is also for Arduino, not raspberry pi).
Here is a screen capture of the model:
Here is block "ChannelA" properties (Note in the advanced tab, enable comparator is not checked):
Here is block "ChannelB" properties (Same as Channel A, but selected a different channel):
If the conversation mode is "Single Shot" then both blocks just output channel A.
If the conversation mode is continuous, then both blocks output whatever channel has most recently changed voltage. Very strange. It seems like the i2c information is being sent to both blocks although different channels are selected.
I have all of the hardware breadboarded and the voltages / connections are all correct. Ruled that out.
Some help with this blockset would be appreciated. I cannot seem to get this working. For testing this I am using the Simulink run on hardware feature with my raspberry pi and I am on version R2024a of maltab/simulink.
Thanks - Kyle.

採用された回答

Ayush
Ayush 2024 年 8 月 7 日
編集済み: Ayush 2024 年 8 月 7 日
Hello Kyle,
From the problem that you have described as well as the screenshots attached, it seems the underlying issue may be with the device i.e. ADS1X15, more specifically with its synchronization to read multiple channels to run in a "single-shot" conversion mode where it could wait for a specified amount of time and then set the next channel. You may achieve the same by creating a custom MATLAB Function block that simulates simultaneous reads in quick succession between the channels with a chosen delay as per the data rate. Here is an example code for your reference for the MATLAB Function block:
function [dataA, dataB] = readMultipleChannels()
coder.extrinsic('i2cdev', 'write', 'read');
persistent i2cObj;
if isempty(i2cObj)
i2cObj = i2cdev('Raspberry Pi', '0x48'); % Replace '0x48' with your ADS1x15 I2C address
end
% Read from Channel A
dataA = readChannel(i2cObj, 0);
% Read from Channel B
dataB = readChannel(i2cObj, 1);
end
function data = readChannel(i2cObj, channel)
% Set the channel
config = bitor(0x8003, bitshift(channel, 12)); % Single-shot mode
write(i2cObj, config, 'uint16');
% Wait for conversion (depends on data rate, e.g., 8ms for 128SPS)
pause(0.008);
% Read the conversion result
data = read(i2cObj, 2, 'uint16');
end
Hope it helps!
  1 件のコメント
Kyle
Kyle 2024 年 8 月 9 日
Hi Ayush,
Thanks for the reply, I tried something similar to this and it did indeed work. I wanted to use the dedicated blockset but Mathworks has identified the issue and are working on a patch.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRaspberry Pi Hardware についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by