ADS1115 With Simulink / Raspberry Pi (ADS1x15 Block) - Multi-Channel Read Issue?
32 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kyle
am 23 Jul. 2024
Kommentiert: Ghadeer
am 27 Nov. 2024 um 15:47
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.
0 Kommentare
Akzeptierte Antwort
Ayush
am 7 Aug. 2024
Bearbeitet: Ayush
am 7 Aug. 2024
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!
2 Kommentare
Ghadeer
am 27 Nov. 2024 um 15:47
Hi Kyle,
I am facing the same issue with using two ADSX15 blocks where both give me the same exact output. Could you please share the MATLAB function code that you used and worked for you? The above code did not work for me
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Raspberry Pi Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!