PCF8575 error in VSM

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
HenrikH2011
Professional User
Posts: 2
Joined: Fri 2022-02-11 11:32
Location: Denmark

PCF8575 error in VSM

Post by HenrikH2011 »

Hello - Anybody know how to get PCF8575 to work in VSM?

Can't get PCF8575 to work in VSM (16-bit LED driver
PCF8574 do work fine, same SCH design (8-bit LED driver)

Arduino uno standard Proteus templet
Proteus Project attached

- Henrik Hansen
____________________________________________________________________________________
VS-Code:
/* Main.ino file generated by New Project wizard
* Proteus VSM Project
* Created: Thu Sep 5 2013
* Processor: ATmega328P
* Compiler: Arduino AVR
*/

// -----------------------------------------------------------------

// Arduino Uno, PCF8575 LED Driver TEST
// Henrik Hansen - Januar 2023
// GitHub, VS Code/PlatformIO Project: Arduino_UNO_PCF8575_LED_Driver

#include <Arduino.h>
#include <Wire.h>

#define PCF8574_ADDRESS 0x20 // I2C address of the PCF8574 - addr. bit A0:0, A1:0, A2:0
#define PCF8575_ADDRESS 0x21 // I2C address of the PCF8575 - addr. bit A0:1, A1:0, A2:0
// NOT IN USE: #define LED_PIN 0 // LED nr. of the LED on PCF8575. Used to control a specific LED. ex. Wire.write(1 << LED_PIN); - will set LED_PIN HIGH

void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);

Wire.begin();

}

void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("LED ON");
delay(250);

// HH, 19/10-22, Basic Blink and Serial monitor test
/*
digitalWrite(LED_BUILTIN, LOW);
delay(500);
Serial.println("LED OFF");

Serial.println("blink on/off loop ended");
Serial.println("New blink on/off startes in nTime");
Serial.println(" ");
delay(1000);
*/

for (int i = 0; i < 10; i++)
{

// PCF8574 LED Driver, I2C Wire.h
Wire.beginTransmission(PCF8574_ADDRESS);
Wire.write(0x00);
Wire.endTransmission();
delay(250);

Wire.beginTransmission(PCF8574_ADDRESS);
Wire.write(0xFF);
Wire.endTransmission();
delay(500);

// PCF8575 LED Driver, I2C Wire.h
Wire.beginTransmission(PCF8575_ADDRESS);
Wire.write(0x0000);
Wire.endTransmission();
delay(250);

Wire.beginTransmission(PCF8575_ADDRESS);
Wire.write(0xFFFF);
Wire.endTransmission();
delay(500);

} // For loop END

} // void loop END
Attachments
LCS_PCF8575_Port-Expender_000 [20230116, 16-40-11].pdsprj
Arduino_PCF8575_and_PCF8574_LED-Driver
(37.5 KiB) Downloaded 51 times
Ettore
Labcenter Staff
Posts: 2932
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: PCF8575 error in VSM

Post by Ettore »

Several mistakes, both in your code and schematic.
1) Wire.write sends one byte. You should send multiple bytes if you need sending a word. So replace your PCF8575 driver with this one.

Code: Select all

 // PCF8575 LED Driver, I2C Wire.h
   Wire.beginTransmission(PCF8575_ADDRESS);
   Wire.write(0x00);
   Wire.write(0x00);
   Wire.endTransmission();
   delay(250);

   Wire.beginTransmission(PCF8575_ADDRESS);
   Wire.write(0xFF);
   Wire.write(0xFF);
   Wire.endTransmission();
   delay(500);
2) U5 and U6 are placed in the wrong way around.
Kind regards,
Ettore Arena - Labcenter Electronics.
HenrikH2011
Professional User
Posts: 2
Joined: Fri 2022-02-11 11:32
Location: Denmark

Re: PCF8575 error in VSM

Post by HenrikH2011 »

Hi Ettore - Thanks for your quick reply
Yes U5 and U6 wrong way around - that was a mistake I had just overlooked - Thanks

With Your code it works now -
Wire.beginTransmission(PCF8575_ADDRESS);
Wire.write(0x00);
Wire.write(0x00);
Wire.endTransmission();
delay(250);

The Wire.write(0x0000); I got from ChatPGT - for 16-pin :-)
ChatPGT replay:
It's also important to note that you need to set the number of pins that you are using in the PCF8575, if you are using 16 pins then you can use 0xFFFF or 0x0000 to turn on or off all the LEDs, respectively.

ChatGPT seems really good for quickly finding help, and not spending a long time Googling, but, yes, it is a development project and here the AI robot was wrong :-)

Thanks for the quick help
Yours sincerely
Henrik Hansen
Post Reply