This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PGA460-Q1: PGA460-Q1 and Arduino

Part Number: PGA460-Q1
Other Parts Discussed in Thread: ENERGIA, PGA460, PGA460PSM-EVM, MSP-EXP430F5529LP

Hi there,

I need Arduino code for try PGA460 ultrasonic proximity-sensing evaluation module. I need this too much and urgently. If somebody have, please could you share with me? I know, sample code exists for Energia and is very long. I have to edit it for Arduino ide and try it with Arduino board. 

Please help me.

Thanks

  • Hi Lacin,

    If you are having trouble porting the PGA460 Energia project to Arduino, I recommend that you post your request to the Arduino Community Forum at ( https://forum.arduino.cc/ ). I am certain a community member there can help guide you on porting this project to the Arduino IDE.

  • Lacin,

    You can also use the following non-library implementation of the bare minimum requirements to run the PGA460 on Energia or Arduino. This example starts-up and configures the device to loop a burst-and-listen command. The command to read back the ultrasonic measurement results has not been finalized (see TODO line in run loop function) in this example:

    //note: minimum requirement example used to send a burst/listen command to PGA460
    
    //cmd 0 - p1 burst listen
    byte buf0[4] = {0x55, 0x00, 0x01, 0xFE};
    //cmd 1 - p2 burst listen
    byte buf1[4] = {0x55, 0x01, 0x01, 0xFD};
    //cmd 5 - ultrasonic measurement (assume UART_ADDR=0)
    byte buf5[4] = {0x55, 0x05, 0xFA};
    //cmd 10 - register write decple to time of 4.096ms
    byte buf10[5] = {0x55, 0x0A, 0x26, 0x00, 0xCF};
    //cmd 17 - broadcast p1 burst listen
    byte buf17[4] = {0x55, 0x11, 0x01, 0xED};
    //cmd 19 - broadcast p1 listen only
    byte buf19[4] = {0x55, 0x13, 0x01, 0xEB};
    //cmd 25 - broadcast bulk threshold write
    byte buf25[35] =  {0x55, 0x19, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x84, 0x21, 0x08, 0x42, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x84, 0x21, 0x08, 0x42, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x7C};
    
    const int buttonPin = PUSH2;     // the number of the pushbutton pin
    const int ledPin = RED_LED;      // the number of the LED pin
    int buttonState = 0;         // variable for reading the pushbutton status
    
    void setup() { 
    
      pinMode(ledPin, OUTPUT);
      pinMode(buttonPin, INPUT_PULLUP);
      delay(1000);
      
      // put your setup code here, to run once:
      Serial1.begin(19200);  // initialize PGA460 UART serial channel
      delay(1000);
    
      //assume UART_ADDR=0
      //bulk threshold write mid-code values to clear THR_CRC_ERR
      Serial1.write(buf25, sizeof(buf25));
      delay(100);
     
      // set UART_ADDR=0's time decouple to 4.096ms
      Serial1.write(buf10, sizeof(buf10));
      delay(100);
    }
    
    void loop() {
        // put your main code here, to run repeatedly: 
      
        // check if the pushbutton is pressed.
        while (digitalRead(buttonPin) == HIGH){}
        
        // broadcast p1 burst+listen (non-dependent on UART_ADDR)
        Serial1.write(buf17, sizeof(buf17));
        
        // delay by 100ms
        delay(100);
    
        //[TODO] print ultrasonic measurement results on terminal
        // read back ultrasonic meas results from UART_ADDR=0
        Serial1.write(buf5, sizeof(buf5));
      
        // toggle red LED
        digitalWrite(ledPin, !(digitalRead(ledPin)));   // turn the LED on (HIGH is the voltage level)
    
        // repeat loop every second
        delay (1000);      
    }

  • Hi there,

    Is this basicly enough to use PGA460EVM module with Arduino? 

    Thanks for your reply.

  • Hi Lacin,

    Yes, this code snippet is intended to serve as a bare minimum Energia/Arduino example of leveraging the factory default settings of the PGA460 device, which are intended to be used with a 58kHz transducer. As noted in the code, it is currently only capable of sending transmit commands, as it as not been completed to read back results. For this, you would need to implement a Serial.Read function.

    It is likely you will not be using the 58kHz transducer. Since you do not have the full-scale EVM kit to use the GUI at this time to become more familiar with all the register settings, I recommend that you view the Ultrasonic Sensing with the PGA460-Q1 video training series to see how the critical driver and receiver registers should be configured.

    Assuming you are still using the 40kHz UTR-1440K-TT-R transducer as part of the PGA460PSM-EVM, below is an the register configuration used to collect the UTR-1440K-TT-R data in the PGA460PSM-EVM Design Guide ( https://www.ti.com/lit/pdf/tiduek5 ). You will need to implement either several CMD10 (single register write) commands or one CMD12/CMD23 (bulk EEPROM write) and one CMD16/CMD25 (bulk threshold write) command to upload these settings to the device in the sketch. See datasheet table 3 for a description of all UART commands.

    UTR-1440K-TT-R transducer example register configuration for PGA460:

    ;GRID_USER_MEMSPACE
    00 (USER_DATA1),41
    01 (USER_DATA2),11
    02 (USER_DATA3),11
    03 (USER_DATA4),10
    04 (USER_DATA5),FF
    05 (USER_DATA6),FF
    06 (USER_DATA7),00
    07 (USER_DATA8),00
    08 (USER_DATA9),08
    09 (USER_DATA10),20
    0A (USER_DATA11),C6
    0B (USER_DATA12),30
    0C (USER_DATA13),38
    0D (USER_DATA14),50
    0E (USER_DATA15),80
    0F (USER_DATA16),00
    10 (USER_DATA17),00
    11 (USER_DATA18),00
    12 (USER_DATA19),00
    13 (USER_DATA20),00
    14 (TVGAIN0),9D
    15 (TVGAIN1),EE
    16 (TVGAIN2),EF
    17 (TVGAIN3),2D
    18 (TVGAIN4),B9
    19 (TVGAIN5),EF
    1A (TVGAIN6),DC
    1B (INIT_GAIN),03
    1C (FREQUENCY),32
    1D (DEADTIME),80
    1E (PULSE_P1),12
    1F (PULSE_P2),12
    20 (CURR_LIM_P1),72
    21 (CURR_LIM_P2),32
    22 (REC_LENGTH),09
    23 (FREQ_DIAG),00
    24 (SAT_FDIAG_TH),EE
    25 (FVOLT_DEC),7C
    26 (DECPL_TEMP),8F
    27 (DSP_SCALE),00
    28 (TEMP_TRIM),00
    29 (P1_GAIN_CTRL),29
    2A (P2_GAIN_CTRL),29
    2B (EE_CRC),76
    40 (EE_CNTRL),04
    41 (BPF_A2_MSB),89
    42 (BPF_A2_LSB),52
    43 (BPF_A3_MSB),FC
    44 (BPF_A3_LSB),CE
    45 (BPF_B1_MSB),01
    46 (BPF_B1_LSB),99
    47 (LPF_A2_MSB),7F
    48 (LPF_A2_LSB),33
    49 (LPF_B1_MSB),00
    4A (LPF_B1_LSB),67
    4B (TEST_MUX),00
    4C (DEV_STAT0),80
    4D (DEV_STAT1),00
    5F (P1_THR_0),41
    60 (P1_THR_1),11
    61 (P1_THR_2),11
    62 (P1_THR_3),10
    63 (P1_THR_4),FF
    64 (P1_THR_5),FF
    65 (P1_THR_6),00
    66 (P1_THR_7),01
    67 (P1_THR_8),F8
    68 (P1_THR_9),20
    69 (P1_THR_10),C6
    6A (P1_THR_11),30
    6B (P1_THR_12),38
    6C (P1_THR_13),50
    6D (P1_THR_14),80
    6E (P1_THR_15),00
    6F (P2_THR_0),41
    70 (P2_THR_1),11
    71 (P2_THR_2),11
    72 (P2_THR_3),10
    73 (P2_THR_4),FF
    74 (P2_THR_5),FF
    75 (P2_THR_6),00
    76 (P2_THR_7),01
    77 (P2_THR_8),F8
    78 (P2_THR_9),20
    79 (P2_THR_10),C6
    7A (P2_THR_11),30
    7B (P2_THR_12),38
    7C (P2_THR_13),50
    7D (P2_THR_14),80
    7E (P2_THR_15),00
    7F (THR_CRC),F9
    EOF

  • Hello again,

    I resolved problems that <Energia.h>. I must to change <msp460.h> library to <ArduinoUno.h> library. I found address that msp430.h pin library. (C:\Users\Laçin Tuncer\Downloads\energia-1.8.10E23-windows\energia-1.8.10E23\hardware\energia\msp430\variants\MSP-EXP430F5529LP\pins_energia.h). I didn't write header file for arduino before. I don't know how to write. Is this similar to PIC header file?

    Could you control? I opened the project "GetDistance.ino" with Arduino IDE.

    And then, I added library with this path: Sketch>Include Library>Add .ZIP Library> C:\Users\Laçin Tuncer\Desktop\slac741i - Kopya>LIBRARYKOPYA.zip
    When I compiled, it gave error about msp430.h library. And then, I deleted line that <msp430.h> in this file: C:\Users\Laçin Tuncer\Desktop\slac741i - Kopya > LIBRARYKOPYA.zip > pga460_usci_spi_G2553.cpp

    When I compiled again, this time it gave different error. It didn't know pins' names (PUSH2 etc.) Then, I recognized these pins. But it gave error again and again. You can see the error below.

    Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno"

    In file included from C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.cpp:16:0:

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static uint8_t SPIClass::transfer(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:49:12: error: 'spi_send_pga460' was not declared in this scope

    return spi_send_pga460(_data);

    ^~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::begin()':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:54:5: error: 'spi_initialize_pga460' was not declared in this scope

    spi_initialize_pga460();

    ^~~~~~~~~~~~~~~~~~~~~

    In file included from C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_USSC.cpp:37:0:

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static uint8_t SPIClass::transfer(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:49:12: error: 'spi_send_pga460' was not declared in this scope

    return spi_send_pga460(_data);

    ^~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:54:5: note: suggested alternative: '__cpp_initializer_lists'

    spi_initialize_pga460();

    ^~~~~~~~~~~~~~~~~~~~~

    __cpp_initializer_lists

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::end()':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:59:5: error: 'spi_disable_pga460' was not declared in this scope

    spi_disable_pga460();

    ^~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::begin()':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:54:5: error: 'spi_initialize_pga460' was not declared in this scope

    spi_initialize_pga460();

    ^~~~~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::setBitOrder(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:64:5: error: 'spi_set_bitorder_pga460' was not declared in this scope

    spi_set_bitorder_pga460(bitOrder);

    ^~~~~~~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:54:5: note: suggested alternative: '__cpp_initializer_lists'

    spi_initialize_pga460();

    ^~~~~~~~~~~~~~~~~~~~~

    __cpp_initializer_lists

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::end()':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:59:5: error: 'spi_disable_pga460' was not declared in this scope

    spi_disable_pga460();

    ^~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::setDataMode(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:69:5: error: 'spi_set_datamode_pga460' was not declared in this scope

    spi_set_datamode_pga460(mode);

    ^~~~~~~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::setBitOrder(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:64:5: error: 'spi_set_bitorder_pga460' was not declared in this scope

    spi_set_bitorder_pga460(bitOrder);

    ^~~~~~~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::setClockDivider(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:74:5: error: 'spi_set_divisor_pga460' was not declared in this scope

    spi_set_divisor_pga460(rate);

    ^~~~~~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::setDataMode(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:69:5: error: 'spi_set_datamode_pga460' was not declared in this scope

    spi_set_datamode_pga460(mode);

    ^~~~~~~~~~~~~~~~~~~~~~~

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h: In static member function 'static void SPIClass::setClockDivider(uint8_t)':

    C:\Users\La�in Tuncer\Documents\Arduino\libraries\LIBRARYKOPYA\PGA460_SPI.h:74:5: error: 'spi_set_divisor_pga460' was not declared in this scope

    spi_set_divisor_pga460(rate);

    ^~~~~~~~~~~~~~~~~~~~~~

    exit status 1
    Error compiling for board Arduino Uno.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

  • Lacin,

    You likely have a similar library import issue as discussed on your other post: https://e2e.ti.com/support/sensors/f/1023/p/912363/3375615#3375615

    However, you will have a similar problem with the SPI functionality. Repeating some of the Energia-to-Arduino conversion notes from the post your branched from:

    1) Delete the following from the PGA460EnergiaLibrary_vx.x.x library folder: "PGA460_SPI.cpp", "PGA460_SPI.h", "utility" folder. The SPI functions for the PGA460 were customized specifically for the MSP430F5529 microcontroller. SPI support is only enabled through Energia, not Arduino at this time.

    2) Replace all instances of #include <Energia.h> to #include <Arduino.h> in the library files (PGA460_USSC.h/.cpp)

    3) In all files, change any reference of or comment out "PUSH2", "GREEN_LED", "RED_LED" to a Arduino pin numbers. These designators are specific to the Energia.h file for the LaunchPads.

    4) Delete case 3 from the initBoostXLPGA460 function in PGA460_USSC.cpp.

    I've already applied these changes and implemented what I could without physical Arduino hardware in the attached PGA460 Library for Arduino ZIP (beta/untested):

    PGA460EnergiaLibrary_v1.0.9_Arduino.zip

    I was able to get the included GetDistance_Arduino.ino sketch to compile using the ATmega 2560 board. Note, to enable SPI, you will need to write the Arduino code yourself since the PGA460 library's SPI functions though Energia are specific to the TI MSP430. This is why the notes instruct to remove all references of SPI from the original PGA460 library when porting to Arduino; otherwise, it will throw many of the error messages you have shown.