Simple example of I2c code " My World" request

Questions on control of serial busses
basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Simple example of I2c code " My World" request

Post by basicchip »

For true constants you can use the CONST declaration (see the help files)

The SuperPRO was also laid out to accept a serial EEPROM that you can add (it is not loaded normally) In the help files https://www.coridium.us/ARMhelp/index.h ... rPins.html



jmcdougall
Posts: 35
Joined: Tue Mar 22, 2022 11:17 pm

Re: Simple example of I2c code " My World" request

Post by jmcdougall »

A really dumb question!
Previously I had been testing with a graphics display that did not support cursor functions. Now I have the one I need that can do this. Both displays had leds and keypads. I have been teasting the code that worked on the first display now using the newest and have run into a small issue. The commands for turning the three leds on/off and to the three colors all where based around decimal parameters and everything worked fine It used a grid of rows and columns and the values for these were all decimal.

The display I am now using has a different command set and instead of rows and columns, it has a set of 6 GPIOs and on/off for each GPIO. The on/off are different commands and the last parameter is the GPIO as a byte. I have had no problems with characters or decimals being passed in the last parameter(string) in the i2cOut function, but so far it has not worked when I pass a 1, or decimal 49 or 0X01 as the byte parameter What should I put as the string(3)value for either 1 ,2 3 or 4 as a value as a byte

Specifically the LCD_String should look like this to turn Led 1 green
Led 1 uses GPIO 1 and GPIO 2

'turn GPIO 1 off
LCD_String(0) = 254 (decimal)
LCD_String (1) = 56 (decimal) ' turn off
LCD-String (2) = 1 (byte) ' select GPIO 1

'turn GPIO 2 on
LCD_String(0) = 254 (decimal)
LCD_String (1) = 57 (decimal) ' turn on
LCD-String (2) = 2 (byte) ' select GPIO 2

How do structure the LCD string (2) values to represent a byte that is passed to the display?

Thanks!

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Simple example of I2c code " My World" request

Post by basicchip »

I am assuming your (decimal) and (byte) are really comments.

If you defined LCD_String as byte or string, then all the values are 8 bits or byte values. Byte values are 0 to 255. Any other values are truncated to 8 bits and stored in the array

jmcdougall
Posts: 35
Joined: Tue Mar 22, 2022 11:17 pm

Re: Simple example of I2c code " My World" request

Post by jmcdougall »

Yes. They are comments. LCD_String is defined as string yet I havew not had erros when I do the following

LCD_String(0) = 254
LCD_String(1) = 54

even though those are decimal numbers not "254" even though the variable is defined as string.
This has worked fine for me using multiple display commands.
This is the first command I have run across that specifies a "byte" rather than a "number" as a parameter.

The values are either 1,2,3,4,5 or 6 which represent the 6 GPIOs.

As previously indicated, I have tried doing LCD_String(2) = 1
but that does not work, so I am assuming that decimal 1 does not resolve down to a byte value of 1.

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Simple example of I2c code " My World" request

Post by basicchip »

I'm not sure why you think

LCD_String(2) =1

doesn't put a 1 in that byte position, I can assure you it does.

Print it out if you doubt it. Something else is going on.

jmcdougall
Posts: 35
Joined: Tue Mar 22, 2022 11:17 pm

Re: Simple example of I2c code " My World" request

Post by jmcdougall »

Yep Dumb mistake read the wrong command code line.

Everything is working now. All display, led control and keypad read functions are tested. Need to break a big sub that contained all of these parts out into small modular subs that I can call with parameters

Thank you for all your help!

I have decided that there is not enough timing data to justify using external data storage and I can just load it into arrays within the program.
The next piece is going to be measure actual voltage values on a working machine.

jmcdougall
Posts: 35
Joined: Tue Mar 22, 2022 11:17 pm

Re: Simple example of I2c code " My World" request

Post by jmcdougall »

Started building the Main program and have run into few issues with more generic versions of the subs I created when testing.

Issue #1 Passing values into LCD_String using variables and passing a string value as a parameter to a Sub.
I have had no issues doing things like LCDString(1) = 86 or LCDString(0) = MOCommand where MOCommand was Dim'd as Integer'
However this sub is one of two that is giving me a serious headache. It gives an error :
ERROR F:/Enterprise Processor/SuperMainNew.txt: 159: No String Size declared
Sub LedColor (ledid as Integer,color as String,i2cresponse as Integer)
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 202: Undefined Label I2CRESPONSE
i2cresponse = i2cPresent
and a bunch more about the "If color = "xxxx"

Sub LedColor (ledid as Integer,color as String,i2cresponse as Integer)
DIM gpioa as Integer
Dim gpiob as Integer
LCD_String(0) = MOCommand
If ledid = 1 then
gpioa = 1
gpiob = 2
ENDIF
If ledid = 2 then
gpioa = 3
gpiob = 4
ENDIF
If ledid = 3 then
gpioa = 5
gpiob = 6
ENDIF

If color = "green" Then
LCD_String(1) = 86 '
LCD_String(2) = gpioa
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
LCD_String(1) = 87
LCD_String(2) = gpiob
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
endif

If color = "yellow" Then
LCD_String(1) = 87 '
LCD_String(2) = gpioa
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
LCD_String(1) = 87
LCD_String(2) = gpiob
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
endif

If color = "red" Then
LCD_String(1) = 87 '
LCD_String(2) = gpioa
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
LCD_String(1) = 86
LCD_String(2) = gpiob
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
endif
i2cresponse = i2cPresent
Return
EndSub



What did I miss in the ArmBasic manual that the above is erroring out
Note that I do not have a call to this Sub in the Main section yet.

jmcdougall
Posts: 35
Joined: Tue Mar 22, 2022 11:17 pm

Re: Simple example of I2c code " My World" request

Post by jmcdougall »

Isssue #2 Handling the return value from the I2cIn

So from experimentation, I know that I get a value of 67 or 68 or etc returned in LCD_DATA(0). It is the decimal value of the characters that the buttons are mapped to.
I get the following errors:
ERROR F:/Enterprise Processor/SuperMainNew.txt: 218: No String Size declared
Sub GetKeypad(keypadval as String)
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 218: Function/Sub syntax error
Sub GetKeypad(keypadval as String)
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 235: expected comparison operator
if LCD_DATA(0) = "65" then
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 235: Expected Operand
if LCD_DATA(0) = "65" then
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 237: ENDIF Without IF
EndIF
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 238: expected comparison operator
if LCD_DATA(0) = "66" then
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 238: Expected Operand
if LCD_DATA(0) = "66" then
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 240: ENDIF Without IF
EndIF
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 241: expected comparison operator
if LCD_DATA(0) = "67" then goto
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 241: Expected Operand
if LCD_DATA(0) = "67" then goto
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 242: Expected lvalue: variable, pointer, or register
EXIT1
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 243: ENDIF Without IF
EndIF


Here is the code- it is not complicated but in the If statements should I be comparing to the char instead of the decimal?



Sub GetKeypad(keypadval as String)
Dim i as Integer
DIM LCD_CMD(8) as String
DIM LCD_DATA(16) as String
LCD_CMD(0) = 254 '
LCD_CMD(1) = 38 ' get last keypress value

i = 1

Do
I2CIN(10,11,80,2,LCD_CMD,16,LCD_DATA)
print "Data0 = "; LCD_DATA(0)


If LCD_DATA(0) = "0" then
goto EXIT1
ENDIF
if LCD_DATA(0) = "65" then
goto EXIT1
EndIF ' A upper Left - Yes
if LCD_DATA(0) = "66" then
goto EXIT1
EndIF ' B move up
if LCD_DATA(0) = "67" then goto
EXIT1
EndIF ' C move right
if LCD_DATA(0) = "68" then
goto EXIT1
EndIF ' D move left
if LCD_DATA(0) = "69" then
goto EXIT1
EndIF ' E Select
if LCD_DATA(0) = "71" then
goto EXIT1
EndIF ' G lower left - No
if LCD_DATA(0) = "72" then
goto EXIT1
EndIF ' H move down

wait(1000)
i = i + 1
Loop Until i > 1000
EXIT1:
keypadval = LCD_DATA(0)
print "keypad = ";keypadval
RETURN

End Sub

In the Main section I just do this
GetKeypad(keypadcode)

Interestingly enough, it will not let me Dim keypadcode in the global Dim section

jmcdougall
Posts: 35
Joined: Tue Mar 22, 2022 11:17 pm

Re: Simple example of I2c code " My World" request

Post by jmcdougall »

Issue #3 This doesn't make sense to me.
In the Global Dim area
Dim ProcStep(10) as String

Under the Main section
ProcStep(1) = "Pre-Wash"
ProcStep(2) = "1st Developer"
ProcStep(3) = "Wash"
ProcStep(4) = "Color Developer"
ProcStep(5) = "Wash"
ProcStep(6) = "Blix"
ProcStep(7) = "Running Wash"

Errors with
ERROR F:/Enterprise Processor/SuperMainNew.txt: 572: expected comparison operator
ProcStep(1) = "Pre-Wash"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 572: Expected Operand
ProcStep(1) = "Pre-Wash"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 573: expected comparison operator
ProcStep(2) = "1st Developer"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 573: Expected Operand
ProcStep(2) = "1st Developer"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 574: expected comparison operator
ProcStep(3) = "Wash"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 574: Expected Operand
ProcStep(3) = "Wash"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 575: expected comparison operator
ProcStep(4) = "Color Developer"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 575: Expected Operand
ProcStep(4) = "Color Developer"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 576: expected comparison operator
ProcStep(5) = "Wash"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 576: Expected Operand
ProcStep(5) = "Wash"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 577: expected comparison operator
ProcStep(6) = "Blix"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 577: Expected Operand
ProcStep(6) = "Blix"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 578: expected comparison operator
ProcStep(7) = "Running Wash"
-ERROR F:/Enterprise Processor/SuperMainNew.txt: 578: Expected Operand
ProcStep(7) = "Running Wash"

Can you not use an "=" to assign a text string to an array value?

Same issue with
' Display E6Menu
menu(1) = "Arista E6 >"
menu(2) = "Edwal E6 >"
menu(3) = "Unicolor E6 >"
menu(4) = "Film Proc Prjt E6 >"


Thank you

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Simple example of I2c code " My World" request

Post by basicchip »

Dim ProcStep(10) as String

Declares an array of 10 bytes. Each byte contains 1 character.

To access a single byte in ProcStep you use the parenthesis

ProcStep (1) = 12 ' assigns a single byte to byte 1 of that array -- arrays have indices of 0 to 10 by your definition

ProcStep = "a thing" ' assigns all 7 characters to indices 0 to 6 followed by 0 in ProcStep(7)

The help files show this, but the help files are not a language tutorial, but this is the way most all languages work though C uses []

Also you declared ProcStep to be 10 bytes, but some of your constants exceed 10 bytes

Post Reply