Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:26 27 Nov 2024 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 : i2c and spi

Author Message
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 11:04pm 17 Dec 2023
Copy link to clipboard 
Print this post

I got mcp23017 port expander and ssd1306 on same i2c to show buttons pressed as binary and works fine...button pad is not as simple to make as seems :)
When wired to ili9341 it displays 00000000, so display is working ... but on ssd1306 it's 11111111 for no buttons pressed. works well, pressing 8 buttons gives 00000000.
for it to flash needed
'SETPIN gp20, gp21, I2C
'I2C OPEN 100,100
it don't work with ili9341??

dim integer portabits
'SETPIN gp20, gp21, I2C
'I2C OPEN 100,100

const mcp23017 = &h20 ' A2, A1, A0, R/W all connected to 0V
Const i2caddr=mcp23017
const IODIRA = &h00 ' Port A IO Direction register DEFAULT = I/P
const IODIRB = &h01 ' Port B IO Direction register DEFAULT = I/P
const IOCON = &h0A ' IO Expander config register - address &h0B accesses  same register
const GPIOA = &h12 ' Port A General purpose register
const GPIOB = &h13 ' Port B General Purpose register
const OLATA = &h14 ' Port A latch register
const OLATB = &h15 ' Port B latch register
const GPUPA = &h0C ' Port C pull-up register
const GPUPB = &h0D ' Port B pull-up register
'
I2C WRITE MCP23017,0,2,IODIRA,255 ' set direction to input
I2C WRITE MCP23017,0,2,IODIRB,255 ' set direction to input
I2C WRITE MCP23017,0,2,GPUPB,&hff ' set weak pullups on all
'
Font 2
CLS
'
Do

'then when you read:
I2C WRITE MCP23017,0,1,GPIOB ' set the register to read
I2C READ MCP23017,0,1,portabits ' read the B port

text 0,20,bin$(portabits,8)
Pause 100
Loop




Edited 2023-12-18 09:06 by stanleyella
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 11:36pm 17 Dec 2023
Copy link to clipboard 
Print this post

this is the ili board so 'SETPIN gp20, gp21, I2C not used?? ok for i2c?
> option list
PicoMite MMBasic Version 5.07.08RC18
OPTION SYSTEM SPI GP18,GP19,GP16
OPTION AUTORUN  ON
OPTION CPUSPEED  378000 'KHz
OPTION LCDPANEL ILI9341, LANDSCAPE,GP15,GP14,GP13
OPTION TOUCH GP12,GP11
GUI CALIBRATE 0, 3918, 3699, -895, -681
OPTION SDCARD GP22
>
OPTION SYSTEM I2C GP20,GP21 gives
Error : Pin 26/GP20 is in use
Edited 2023-12-18 09:55 by stanleyella
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 11:55pm 17 Dec 2023
Copy link to clipboard 
Print this post

Why do you think that the difference between your readings is because of the display you are using to show the reading?

What do you get if instead of writing to the display, you write to the console?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 12:27am 18 Dec 2023
Copy link to clipboard 
Print this post

What happens if you change to:-

OPTION SYSTEM I2C GP2,GP3 'second I2C

Something seems to be tying up either GP20 or the first I2C.

As Lizby said what sort of display you use shouldn't matter, in any case printing to the console always shows what is really going on.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4237
Posted: 06:25am 18 Dec 2023
Copy link to clipboard 
Print this post

Are the keys connected to port a. Or to port b.?
You are reading GPIOB into the value portAbits.
Confusing.?

Volhout
PicomiteVGA PETSCII ROBOTS
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 03:52pm 18 Dec 2023
Copy link to clipboard 
Print this post

  Volhout said  Are the keys connected to port a. Or to port b.?
You are reading GPIOB into the value portAbits.
Confusing.?

Volhout

I'm reading portB, should have changed the var name to portBbits.
It works with it wired to same i2c as the ssd1306, it's the i2c and spi ili9341 which is a different board and pico.
I will try another i2c device that works with ssdi306 but use ili9341.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 05:00pm 18 Dec 2023
Copy link to clipboard 
Print this post

I used OPTION SYSTEM I2C gp0,gp1 and it works with ili9341 board ok now??
Is option reset the only way now to change the system i2c now to other pins?


Edited 2023-12-19 05:06 by stanleyella
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 08:57pm 18 Dec 2023
Copy link to clipboard 
Print this post

  Quote  Is option reset the only way now to change the system i2c now to other pins?

To change a single Option first Disable it then apply the new settings.
eg:
OPTION SYSTEM I2C Disable

OPTION SYSTEM I2C GP0,GP1
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 09:49pm 18 Dec 2023
Copy link to clipboard 
Print this post

  phil99 said  
  Quote  Is option reset the only way now to change the system i2c now to other pins?

To change a single Option first Disable it then apply the new settings.
eg:
OPTION SYSTEM I2C Disable

OPTION SYSTEM I2C GP0,GP1

Thanks phil, better than set it all up again I'm dim. wanted wires same side as 3.3v out. Thanks to all for the code to get mcp23017 expander working.
it's old chip but still useful and cheap. i2c can be difficult to understand and it's device parameters to understand , data sh*ts,no way but a bit of code from someone helps a lot more :)
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 10:50pm 18 Dec 2023
Copy link to clipboard 
Print this post

like ssd1306 i2c the i2c range finder works ok with spi. when i2c works it's nice.

 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024