Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:56 06 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Help with Arrays

     Page 1 of 2    
Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 12:34pm 27 Apr 2016
Copy link to clipboard 
Print this post

Little lost here, can someone explain what I'm doing wrong?

Original Code:-

'1-Wire Serial Number Search - One Device ONLY Attached.
'Code by Jman 02 April 2016
Option Explicit
Dim OW1,OW2,OW3,OW4,OW5,OW6,OW7,OW8
Dim PinNbr
PinNbr = 22

OneWire Reset Pinnbr
OneWire Write PinNbr, 1, 1, &H33 ' Issue Read ROM command
OneWire Read PinNbr, 2, 8, OW1,OW2,OW3,OW4,OW5,OW6,OW7,OW8

Print "Temp Sensor Should be 28 / ";Hex$(OW1);"H"
Print "Ser# ",Hex$(OW2,2);Hex$(OW3,2);Hex$(OW4,2);Hex$(OW5,2);Hex$(OW6,2);Hex$(OW7,2);"H"
Print "CRC ";Hex$(OW8,2);"H"


My Attempt to implement an Array:-

Option Explicit
Dim OW(9)
Dim PinNbr
PinNbr = 22

OneWire Reset Pinnbr
OneWire Write PinNbr, 1, 1, &H33 ' Issue Read ROM command
OneWire Read PinNbr, 2, 8, OW(1),OW(2),OW(3),OW(4),OW(5),OW(6),OW(7),OW(8)

Print "Temp Sensor Should be 28 / ";Hex$(OW(1);"H"
Print "Ser# ",Hex$(OW(2),2);Hex$(OW(3),2);Hex$(OW(4),2);Hex$(OW(5),2);Hex$(OW(6),2);Hex$(OW(7),2);"H"
Print "CRC ";Hex$(OW(8),2);"H"


Returns:-
[10] OneWire Read PinNbr, 2, 8, OW(1),OW(2),OW(3),OW(4),OW(5),OW(6),OW(7),OW(8)
Error: Invalid variable
>


Thanks

Phil.
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 01:38pm 27 Apr 2016
Copy link to clipboard 
Print this post

From the Micromite manual concerning 1-Wire Communications:

  Quote  You cannot use an array or string variable for 'data'. One or more numeric variables are required


Sorry

--CurtisEdited by Justplayin 2016-04-28
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 02:56pm 27 Apr 2016
Copy link to clipboard 
Print this post

Thanks Curtis,

Skipped over that block when I read "For users of MMBasic on earlier devices".
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 11:42am 09 May 2016
Copy link to clipboard 
Print this post

Still like to get all my Serial Numbers into an array,
even though I will need to convert them to variables inside the sub for use.

Ie:-

Dim Float Ts(7,6) 'Serial Numbers for 6 sensors.

Then use something like OW1=Ts(1,1),OW2=Ts(1,2),......

Not sure how to load the array; getting variable type errors just trying to get hex values into the array.

Option Autorun On
Option Explicit
Option Default None
Option Base 1
'Serial#'s & CRC of DS18B20 Temp Sensors.
'Const Ts1a=&H24,Ts1b=&H72,Ts1c=&H4A,Ts1d=&H07,Ts1e=&H00,Ts1f=&H00,Ts1g=&H1B 'Temp Sensor 1
Const Ts2a=&HC9,Ts2b=&H5D,Ts2c=&H4B,Ts2d=&H07,Ts2e=&H00,Ts2f=&H00,Ts2g=&H60 'Temp Sensor 2
Const Ts3a=&H46,Ts3b=&HB9,Ts3c=&H4A,Ts3d=&H07,Ts3e=&H00,Ts3f=&H00,Ts3g=&HE4 'Temp Sensor 3

Dim Float Ts (7,3)
Ts(1,1)=&H24,Ts(2,1)=&H72,Ts(3,1)=&H4A,Ts(4,1)=&H07,Ts(5,1)=&H00,Ts(6,1)=&H00,Ts(7,1)=&H1B 'Temp Sensor 1


The Code using Constants works, just think it's a bloated approach.

10 Sensors for example, will need 10 lines of 7 variables.

Would be better with a 7x10 Array & then convert the aray values over to something like:-

Ts1, Ts2,...... Ts7 inside the sub


Any thoughts?

Thanks

Phil
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 12:38pm 09 May 2016
Copy link to clipboard 
Print this post

Also wonder is I could use something like DATA & READ, to get the serial numbers from a list like this?

[Code]DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B,
&HC9,&H5D,&H4B,&H07,&H00,&H00,&H60,
&H46,&HB9,&H4A,&H07,&H00,&H00,&HE4
[/code]

Don't know if there is an operator that will allow the data to be split over multiple lines, but it would be good if it could as it makes the above list very easy to read.

Cheer.
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 12:48pm 09 May 2016
Copy link to clipboard 
Print this post

  Phil23 said  

Dim Float Ts (7,3)
Ts(1,1)=&H24,Ts(2,1)=&H72,Ts(3,1)=&H4A,Ts(4,1)=&H07,Ts(5,1)=&H00,Ts(6,1)=&H00,Ts(7,1)=&H1B 'Temp Sensor 1


You have a couple of errors here...

Drop the Float, its the default data type. No space between Ts and (7,3). And instead of commas between each statement you need colons.


Dim Ts(7,3)
Ts(1,1)=&H24: Ts(2,1)=&H72: Ts(3,1)=&H4A: Ts(4,1)=&H07: Ts(5,1)=&H00: Ts(6,1)=&H00: Ts(7,1)=&H1B 'Temp Sensor 1



And if your want to use DATA statements you will need to start each DATA line with the DATA statement.

--CurtisEdited by Justplayin 2016-05-10
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 01:57pm 09 May 2016
Copy link to clipboard 
Print this post

  Justplayin said  And if your want to use DATA statements you will need to start each DATA line with the DATA statement.

--Curtis


So with Data using multiple lines, how do I choose which line to READ?

[Code]
DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3
[/code]

Presume that's what the first bit would look like. Can't find a lot of detail on READ.

Cheers.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 02:05pm 09 May 2016
Copy link to clipboard 
Print this post

  Quote  RESTORE [line]
Resets the line and position counters for the READ statement.
If ‘line’ is specified the counters will be reset to the beginning of the
specified line. ‘line’ can be a line number or label.
If ‘line’ is not specified the counters will be reset to the start of the program.


If you label each line, you can RESTORE to the line you want.
Alternatively, if you want to step through all devices in turn, you don't have to worry about RESTORE for each device.

Jim
VK7JH
MMedit
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 03:53pm 09 May 2016
Copy link to clipboard 
Print this post

Phil,

Although you can use RESTORE to reload your DATA, it is generally not done unless you are effectively restarting your program by going back to the beginning. Once you load your data into an array you are done with the DATA statements and you simply reuse the data in the array over and over, reading from any location in the array at any time.

Sorry... In the example below I switched your array order around to something more logical to me. I had already written the example before I saw the switch and I'm too lazy (and in a bit of a rush) to fix it right now.


Dim Ts(3,7) ' Ts(sensor #, id data)

DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3

For i = 1 to 3 'sensor # count
For j = 1 to 7 'id byte count
Read Ts(i,j) 'read the data in the array
Next j
Next i

'** We no longer need the DATA statements, it's now all stored in the array

'** Show the array contents
For i = 1 to 3
For j = 1 to 7
Print "Ts("; i;",";j ;") = "; Ts(i,j); " ";
Next j
print
Next i

'** output a couple of values from the array
Print
Print
Print Ts(2,4) ' sensor 2, byte 4
Print Ts(3,5) ' sensor 3, byte 5
Print Ts(1,2) ' sensor 1, byte 2

End



Arrived at my destination so I can post a update with the array like your original:

Dim Ts(7,3) ' Ts(id data, sensor #)

DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3

For i = 1 to 3 'sensor # count
For j = 1 to 7 'id byte count
Read Ts(j,i) 'read the data in the array
Next j
Next i

'** We no longer need the DATA statements, it's now all stored in the array

'** Show the array contents
For i = 1 to 3
For j = 1 to 7
Print "Ts("; j;","; i;") = "; Ts(j,i); " ";
Next j
print
Next i

'** output a couple of values from the array
Print
Print
Print Ts(4,2) ' byte 4, sensor 2
Print Ts(5,3) ' byte 5, sensor 3
Print Ts(2,1) ' byte 2, sensor 1

End



--CurtisEdited by Justplayin 2016-05-11
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 11:09pm 09 May 2016
Copy link to clipboard 
Print this post

Thanks Curtis,

That looks like a good approach.

This project will ultimately require 4 Sensors, plus integration with 5 existing thermistors in a heat pump unit.

The other project on the drawing board will involve at least 8, so having a nice easy to read & edit the serial Number list will be very beneficial.

Can the Data & Array contain mixed variables?


DATA TempOut,&H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1 Outside
DATA TempRof,&HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2 Roof Cavity
DATA TempLrm,&H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3 Lounge Room



Phil
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 07:03am 10 May 2016
Copy link to clipboard 
Print this post

DATA TempOut,&H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1 Outside
DATA TempRof,&HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2 Roof Cavity
DATA TempLrm,&H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3 Lounge Room


Variables within DATA statements in not allowed. DATA statements are great for loading initial values that are the same every time you run a program. Also great for loading large amounts of data such as font tables, CRC tables or names and addresses. After you read the data you can alter the copy stored the variables, but it will not change the original values in the DATA statements

Dim Location$(7), Ts(7,3) ' Ts(id data, sensor #)

DATA "Outside" ,&H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA "Roof Cavity", &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA "Lounge Area", &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3

For i = 1 to 3 'sensor # count
Read Location$(i)
For j = 1 to 7 'id byte count
Read Ts(j,i) 'read the data in the array
Next j
Next i

'** Show the array contents
For i = 1 to 3
Print "Sensor #"; i; " - ID#: ";
For j = 1 to 7
Print Hex$(Ts(j,i),2);
Next j
print " - "; Location$(i)
Next i

End


In this example I have added a string array for the location description and added the data to the DATA statements. Simply make sure you read the DATA in the same order as it is found in the DATA statements.

This does exactly the same as above but with DATA in laid out differently:
Dim Location$(7), Ts(7,3) ' Ts(id data, sensor #)

DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3
DATA "Outside" , "Roof Cavity", "Lounge Area"

'** Read Sensor ID bytes
For i = 1 to 3 'sensor # count
For j = 1 to 7 'id byte count
Read Ts(j,i) 'read the data in the array
Next j
Next i

'** Read Location Description
For k = 1 to 3
Read Location$(k)
Next k

'** Show the array contents
For i = 1 to 3
Print "Sensor #"; i; " - ID#: ";
For j = 1 to 7
Print Hex$(Ts(j,i),2);
Next j
print " - "; Location$(i)
Next i


--Curtis

I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 01:21pm 13 May 2016
Copy link to clipboard 
Print this post

Thanks Curtis,

That helped a lot.

Can anyone see where I'm going wrong from there.

These first portions of code work Ok....

[Code]
'Serial#'s & CRC of DS18B20 Temp Sensors.
Const Ts1a=&H24,Ts1b=&H72,Ts1c=&H4A,Ts1d=&H07,Ts1e=&H00,Ts1f=&H00,Ts1g=&H1B 'Temp Sensor 1
Const Ts2a=&HC9,Ts2b=&H5D,Ts2c=&H4B,Ts2d=&H07,Ts2e=&H00,Ts2f=&H00,Ts2g=&H60 'Temp Sensor 2
Const Ts3a=&H46,Ts3b=&HB9,Ts3c=&H4A,Ts3d=&H07,Ts3e=&H00,Ts3f=&H00,Ts3g=&HE4 'Temp Sensor 3

Sub GetTemps

OneWire Reset PinTmp

OneWire Write PinTmp, 1, 10, &H55,&H28,Ts1a,Ts1b,Ts1c,Ts1d,Ts1e,Ts1f,Ts1g,&H44 'Sensor1
StatusCheck 'check sensor is ready
OneWire Write PinTmp, 1, 10, &H55,&H28,Ts1a,Ts1b,Ts1c,Ts1d,Ts1e,Ts1f,Ts1g,&HBE 'Sensor1
OneWire Read PinTmp, 2, 2, LTemp, HTemp
TempCalc 'Work out the temp in C
TmpCur=Value

OneWire Write PinTmp, 1, 10, &H55,&H28,Ts2a,Ts2b,Ts2c,Ts2d,Ts2e,Ts2f,Ts2g,&H44 'Sensor2
StatusCheck 'check sensor is ready
OneWire Write PinTmp, 1, 10, &H55,&H28,Ts2a,Ts2b,Ts2c,Ts2d,Ts2e,Ts2f,Ts2g,&HBE 'Sensor2
OneWire Read PinTmp, 2, 2, LTemp, HTemp
TempCalc 'Work out the temp in C
TmpInp=Value

OneWire Write PinTmp, 1, 10, &H55,&H28,Ts3a,Ts3b,Ts3c,Ts3d,Ts3e,Ts3f,Ts3g,&H44 'Sensor3
StatusCheck 'check sensor is ready
OneWire Write PinTmp, 1, 10, &H55,&H28,Ts3a,Ts3b,Ts3c,Ts3d,Ts3e,Ts3f,Ts3g,&HBE 'Sensor3
OneWire Read PinTmp, 2, 2, LTemp, HTemp
TempCalc 'Work out the temp in C
TmpOut=Value

End Sub
[/code]

But when I try to use the array data, just one the 1st sensor at this stage, it fails to read Sensor1.

[Code]
Dim Float Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7,I,J
Dim Float Ts (7,3)

DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3

For I = 1 to 3 'Sensor # count = 3 'Load the data into the Array
For J = 1 to 7 'id byte count
Read Ts(J,I) 'read the data in the array
Next J
Next I


Sub GetTemps
Ts1=Ts(1,1):Ts2=Ts(2,1):Ts3=Ts(3,1):Ts4=Ts(4,1):Ts5=Ts(5,1):Ts6=Ts(6,1):Ts7=Ts(7,1) 'Temp Sensor 1 copied from Array to Variables.

OneWire Reset PinTmp

OneWire Write PinTmp, 1, 10, &H55,&H28,Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7,&H44
StatusCheck 'check sensor is ready
OneWire Write PinTmp, 1, 10, &H55,&H28,Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7,&HBE
OneWire Read PinTmp, 2, 2, LTemp, HTemp

TempCalc 'Work out the temp in C
TmpCur=Value
.
.
.
.
End Sub
[/code]

Is it something causing the values to be passed to the OneWire command as decimal & not HEX?

Trying to reduce the code down to a sub that I can call with the Array data.

Thanks

Phil.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4036
Posted: 08:37pm 13 May 2016
Copy link to clipboard 
Print this post

Not so much Decimal as Float maybe?

I don't know if it's because you've used Float arrays but you don't seem to need them in most of the code so maybe try using integers.

John
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 11:39am 14 May 2016
Copy link to clipboard 
Print this post

Same result when I change Ts1-Ts7 & Ts Array to INTEGER.

Totally Miffed now!

Just check the array data, it's full of E4 Hex, 228 Decimal.
[Code]> Print Ts(1,1);Ts(2,1);Ts(3,1);Ts(4,1);Ts(5,1);Ts(6,1);Ts(7,1)
228 228 228 228 228 228 228
>[/code]

Original code loads the data to the array fine.
[Code]
Dim Ts(7,3) ' Ts(id data, sensor #)

DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3

For i = 1 to 3 'sensor # count
For j = 1 to 7 'id byte count
Read Ts(j,i) 'read the data in the array
Next j
Next i

'** We no longer need the DATA statements, it's now all stored in the array

'** Show the array contents
For i = 1 to 3
For j = 1 to 7
Print "Ts("; j;","; i;") = "; Ts(j,i); " ";
Next j
print
Next i

'** output a couple of values from the array
Print
Print
Print Ts(4,2) ' byte 4, sensor 2
Print Ts(5,3) ' byte 5, sensor 3
Print Ts(2,1) ' byte 2, sensor 1

Ts1=Ts(1,1):Ts2=Ts(2,1):Ts3=Ts(3,1):Ts4=Ts(4,1):Ts5=Ts(5,1):Ts6=Ts(6,1):Ts7=Ts(7,1) 'Temp Sensor 1
Print Ts1;Ts2;Ts3;Ts4;Ts5;Ts6;Ts7

End[/code]

Can't for the life of me see any difference apart from variable declarations, which if add to the above don't break it.

[Code]Dim Integer Ts(7,3) ' Ts(id data, sensor #)
Dim Integer Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7[/code]

Edit:- Seems like the FOR NEXT loops in my code are simply being ignored, as if commented out.

Added a line to monitor it on the console & get no output whatsoever.

[Code] For I = 1 to 3 'sensor # count
For J = 1 to 7 'id byte count
Read Ts(J,I) 'read the data in the array
Print J; I; Ts(J,I)
Next J
Next I

pause 10000
[/code]





Edited by Phil23 2016-05-15
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10209
Posted: 12:53pm 14 May 2016
Copy link to clipboard 
Print this post

Try

For I = 1 to 3 'sensor # count
For J = 1 to 7 'id byte count
Read Ts(J,I) 'read the data in the array
Print J, I, Ts(J,I)
Next J
Next I
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 01:05pm 14 May 2016
Copy link to clipboard 
Print this post

And then try

For I = 1 to 3 'sensor # count
For J = 1 to 7 'id byte count
Read t ' read into a temp variable
Ts(J,I) = t 'read the data in the array
Print J, I, Ts(J,I)
Next J
Next I


Some distant memory from the past about reading directly into arrays. Or it could be related to something entirely different...

Jim
VK7JH
MMedit
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 01:23pm 14 May 2016
Copy link to clipboard 
Print this post

Not sure why, but FOR NEXT is now running.

Maybe the Micro didn't update.

Added more debug code:-

[Code]
DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3

Print "FOR - NEXT loop about to start."
For I = 1 to 3 'sensor # count
For J = 1 to 7 'id byte count
Read Ts(J,I) 'read the data in the array
Print J;I;Ts(J,I)
Next J
Next I
Print "FOR - NEXT loop completed"

Print "Array Data:-"
Print Ts(1,1);Ts(2,1);Ts(3,1);Ts(4,1);Ts(5,1);Ts(6,1);Ts(7,1)
Print Ts(1,2);Ts(2,2);Ts(3,2);Ts(4,2);Ts(5,2);Ts(6,2);Ts(7,2)
Print Ts(1,3);Ts(2,3);Ts(3,3);Ts(4,3);Ts(5,3);Ts(6,3);Ts(7,3)
[/code]

This is the output I see in the Console:-

[Code]
RUN
[?25lFOR - NEXT loop about to start.
1 1 36
2 1 114
3 1 74
4 1 7
5 1 0
6 1 0
7 1 27
1 2 201
2 2 93
3 2 75
4 2 7
5 2 0
6 2 0
7 2 96
1 3 70
2 3 185
3 3 74
4 3 7
5 3 0
6 3 0
7 3 228
FOR - NEXT loop completed
Array Data:-
228 228 228 228 228 228 228
228 228 228 228 228 228 228
228 228 228 228 228 228 228

[/code]

Edit: notice the 228; E4 Hex, it is also the last value in the DATA statement.



Edited by Phil23 2016-05-15
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 01:43pm 14 May 2016
Copy link to clipboard 
Print this post

What is strange is this piece of code works perfectly in a separate program file.

[Code]
Dim Integer Ts(7,3) ' Ts(id data, sensor #)
Dim Integer Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7

DATA &H24,&H72,&H4A,&H07,&H00,&H00,&H1B 'Sensor1
DATA &HC9,&H5D,&H4B,&H07,&H00,&H00,&H60 'Sensor2
DATA &H46,&HB9,&H4A,&H07,&H00,&H00,&HE4 'Sensor3

For i = 1 to 3 'sensor # count
For j = 1 to 7 'id byte count
Read Ts(j,i) 'read the data in the array
Print j;i;Ts(j,i)
Next j
Next i

Pause 5000
'** We no longer need the DATA statements, it's now all stored in the array
Do

Print "Array Data:-"
Print Ts(1,1);Ts(2,1);Ts(3,1);Ts(4,1);Ts(5,1);Ts(6,1);Ts(7,1)
Print Ts(1,2);Ts(2,2);Ts(3,2);Ts(4,2);Ts(5,2);Ts(6,2);Ts(7,2)
Print Ts(1,3);Ts(2,3);Ts(3,3);Ts(4,3);Ts(5,3);Ts(6,3);Ts(7,3)
Print

Ts1=Ts(1,1):Ts2=Ts(2,1):Ts3=Ts(3,1):Ts4=Ts(4,1):Ts5=Ts(5,1):Ts6=Ts(6,1):Ts7=Ts(7,1) 'Temp Sensor 1
Print "Sensor1 Values from variables"
Print Ts1;Ts2;Ts3;Ts4;Ts5;Ts6;Ts7

Loop[/code]

Outputs this to the console:-

[Code]
RUN
1 1 36
2 1 114
3 1 74
4 1 7
5 1 0
6 1 0
7 1 27
1 2 201
2 2 93
3 2 75
4 2 7
5 2 0
6 2 0
7 2 96
1 3 70
2 3 185
3 3 74
4 3 7
5 3 0
6 3 0
7 3 228
Array Data:-
36 114 74 7 0 0 27
201 93 75 7 0 0 96
70 185 74 7 0 0 228

Sensor1 Values from variables
36 114 74 7 0 0 27
Array Data:-
36 114 74 7 0 0 27
201 93 75 7 0 0 96
70 185 74 7 0 0 228

Sensor1 Values from variables
36 114 74 7 0 0 27
Array Data:-
36 114 74 7 0 0 27
201 93 75 7 0 0 96
70 185 74 7 0 0 228

Sensor1 Values from variables
36 114 74 7 0 0 27
Array Data:-
36 114 74 7 0 0 27
201 93 75 7 0 0 96
70 185 74 7 0 0 228

Sensor1 Values from variables
36 114 74 7 0 0 27
[/code]

Really can's see I'm doing anything different in the two blocks.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 02:13pm 14 May 2016
Copy link to clipboard 
Print this post

  Phil23 said   Not sure why, but FOR NEXT is now running.

Maybe the Micro didn't update.



Edit: notice the 228; E4 Hex, it is also the last value in the DATA statement.





This probably indicates that you needed a RESTORE statement somewhere.

Hard to know without the full program.

Jim
VK7JH
MMedit
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 02:24pm 14 May 2016
Copy link to clipboard 
Print this post

Thanks Jim,

As I'm only reading the data statement once I presumed I didn't need the restore command.

Data_to_Array.zip is the code that works as expected.

Thermistor_Read.zip is the miss mush of various test code where things don't go as planned.

Ah well, might call it quits for a while & go spend a few hours cutting firewood....


Thanks

Phil.
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025