Jump to content
  • 0

TCS34725 Basys3 VHDL


kmesne

Question

Hi I am trying to use TCS34725 to identify Green and Red Colors, it has I2C interface and i could not find any I2C interface about this and i am not capable to write a protocol code what should I do I am stucked.

I just need when it sees green it turns one led and when it sees red it turns another led.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

You can create a Vivado block design project and add a PmodCOLOR block, an AXI gpio block and a microblaze block. You can customize the PmodColor block to use pmod connector JA. Customize the gpio block to use the leds. You will need to supply an appropriate constraint file. 

The PmodCOLOR block will take care of implementing the i2c protocol and will allow an application created with the SDK to access the color sensor.

You will need to wire your TCS34725 to the pmod according to the PmodCOLOR pinout. In a previous post you mentioned using a color sensor from adafruit. Be very careful to match the pin functions and not the pin numbers. For example, pin1 on the Basys 3 pmod is a data line. Pin 1 on the adafruit TCS34725  is vcc.

After generating a bitfile from your design, you will need to export the hardware including the bitstream and then launch the SDK. The SDK will import the hardware automatically. You can then create an application that reads from the TCS34725, figures out what color light is being sensed and then turn on the appropriate LED.

None of these steps are difficult, but you will need to be familiar with Vivado, the SDK and C to implement them.

Link to comment
Share on other sites

To make sure I was not misleading you, I just put together a project for the Arty using a PmodCOLOR using the technique I described. In addition to the PmodCOLOR block, AXI gpio block and microblaze block, I added an AXI Uart block so rgb values could be dumped to a terminal. You should be able to assemble the blocks on your basys 3. The procedure to build a microblaze based design in vivado can be found here. Follow the microblaze path.

I used the PmodCOLOR demo app as a starting point and extended it to use the AXI gpio to set two leds. If you have the digilent IP library installed, you can find the demo app in 

<vivado-library-install-location>\ip\Pmods\PmodCOLOR_v1_0\drivers\PmodCOLOR_v1_0\examples\main.c

The main loop of the app looks like this. Most of the code is provided in the demo. I added the lines dealing with the leds. There is more to accurately determining color given rgb values, but my simple use of thresholds should suffice for this simple project.

void DemoRun() {
   u8 ID;
   u32 leds;
   COLOR_Data data;
   CalibrationData calib;

   xil_printf("Pmod COLOR Demo launched\r\n");
   ID = COLOR_GetID(&myDevice);
   xil_printf("Device ID = %02x\r\n", ID);

   // Turn on sensor led to illuminate objects passed over the sensor
   COLOR_SetLED(&myDevice,1); 

   data = COLOR_GetData(&myDevice);
   calib = DemoInitCalibrationData(data);
   usleep(2400);

   while (1) {
	  
      data = COLOR_GetData(&myDevice);
      DemoCalibrate(data, &calib);
      data = DemoNormalizeToCalibration(data, calib);
      xil_printf("r=%04x g=%04x b=%04x\n\r", data.r, data.g, data.b);
      
      // Thresholds empirically chosen. 
      // Led1 lights for red object
      // Led2 lights for green object
      leds = data.r > 0x8000 ? 0x01 : 0;  
      leds |= data.g > 0x5000 ? 0x02 : 0;
      XGpio_DiscreteWrite(&myLeds, 1, leds);
      
      usleep(500000);
   }
}

 

Running the app and moving a red object over the sensor produced output similar to this:

Pmod COLOR Demo launched
Device ID = 44
r=0000 g=0000 b=0000
r=0000 g=0000 b=0000
r=0000 g=0000 b=0000
r=0000 g=0000 b=0000
r=0073 g=0026 b=0022
r=0073 g=0026 b=0022
r=0073 g=0026 b=0022
r=0073 g=0026 b=0022
r=384C g=0C3F b=0BFD
r=A84E g=28B0 b=25A1
r=A6B1 g=27EE b=253F
r=A69B g=27F4 b=2544
r=A69B g=27F4 b=2544
r=A69B g=27F4 b=2544
r=9020 g=2339 b=208C
r=9020 g=2339 b=208C
r=0004 g=0003 b=0002
r=0004 g=0003 b=0002


 

Link to comment
Share on other sites

Hi @kmesne,

I agreed will @kwilber that using Microblaze and the IP cores like the Pmod Color IP core will abstract the I2C communication so you will not have to create a I2C controller.

You will also be able to use C instead of HDL(Verilog/VHDL).  

Here is the Getting Started with Digilent Pmod IPs

1) If you are required to use VHDL for this project then I would suggest to look at sites like here and here to help with implementing an I2C controller.

2) Here is a Basys 3 VHDL GPIO demo project that should be helpful with project structure and how to use separate  entities. 

3) I would also suggest looking through the site FPGA4FUN and Asicworld

best regards,

Jon

 

Link to comment
Share on other sites

Hi @kmesne,

Microblaze is a soft core processor available for many of Xilinx FPGA's such as the Artix-7 which is on the Basys 3.  Microblaze processor basically configures the FPGA into a configurable microcontroller.  Here is the Embedded Design Hub - MicroBlaze Soft Processor that should be useful to better understand the processor.

Vivado allows customers to create a block design. In the block design customers can add visual blocks that represent functions/components to the block design.  I would suggest to go through the tutorials on the basys 3 resource center as another starting point as well.

GPIO- Stands for General purpose Input/Output.  Many components use GPIO instead of SPI, I2C or CAN communication to talk between the host and the component.  Here is an article that discusses this.

Here is the WIKI for the Basys 3 VHDL GPIO demo.

The FPGA4FUN and Asicworld links above are good spots to start with learning VHDL and FPGA's.

best regards,

Jon

 

Link to comment
Share on other sites

On 3/26/2019 at 6:31 PM, kwilber said:

You can create a Vivado block design project and add a PmodCOLOR block, an AXI gpio block and a microblaze block. You can customize the PmodColor block to use pmod connector JA. Customize the gpio block to use the leds. You will need to supply an appropriate constraint file. 

The PmodCOLOR block will take care of implementing the i2c protocol and will allow an application created with the SDK to access the color sensor.

You will need to wire your TCS34725 to the pmod according to the PmodCOLOR pinout. In a previous post you mentioned using a color sensor from adafruit. Be very careful to match the pin functions and not the pin numbers. For example, pin1 on the Basys 3 pmod is a data line. Pin 1 on the adafruit TCS34725  is vcc.

After generating a bitfile from your design, you will need to export the hardware including the bitstream and then launch the SDK. The SDK will import the hardware automatically. You can then create an application that reads from the TCS34725, figures out what color light is being sensed and then turn on the appropriate LED.

None of these steps are difficult, but you will need to be familiar with Vivado, the SDK and C to implement them.

 

On 3/27/2019 at 1:03 AM, jpeyron said:

Hi @kmesne,

Microblaze is a soft core processor available for many of Xilinx FPGA's such as the Artix-7 which is on the Basys 3.  Microblaze processor basically configures the FPGA into a configurable microcontroller.  Here is the Embedded Design Hub - MicroBlaze Soft Processor that should be useful to better understand the processor.

Vivado allows customers to create a block design. In the block design customers can add visual blocks that represent functions/components to the block design.  I would suggest to go through the tutorials on the basys 3 resource center as another starting point as well.

GPIO- Stands for General purpose Input/Output.  Many components use GPIO instead of SPI, I2C or CAN communication to talk between the host and the component.  Here is an article that discusses this.

Here is the WIKI for the Basys 3 VHDL GPIO demo.

The FPGA4FUN and Asicworld links above are good spots to start with learning VHDL and FPGA's.

best regards,

Jon

 

Actually i found a vhdl code for it but i have problems with it (https://github.com/ktemkin/VHDL-light-sensors)

I am trying to implement code. But i am really stucked with I2C thing I am not familiar with that. Do I need to create signals at top module for it and do I need to make a constraint for it ?

 and connection of the sensor I tought he did not connect all pins?  do s/he even use top modules or just 2 modules as i2cmaster and tc34725_interface.

Do i need a constraints for inouts ?

Link to comment
Share on other sites

Hi @kmesne,

Typically the top file contains the signals needed as input/output to the FPGA board. Since you are taking data into the FPGA board for this sensor using I2C , then you would need to have these signals in the top file as well as being constrained. Here is a non-digilent tutorial about using I2C with VHDL that should be helpful.

best regards,

Jon

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...