Has anyone tried AI with PICBASIC


+ Reply to Thread
Results 1 to 40 of 111

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,127

    Default Re: Has anyone tried AI with PICBASIC

    I told him that he's using GCbasic syntax instead of PBP, and asked to fix it.

    While he (she, it?) is no longer using GCBasic style subroutine calls, it now uses some C++ syntax

    Code:
    ' PICBASIC PRO code for reading voltage from ADS1115 via I2C
    
    
    ' Define I2C settings
    #IFNDEF __PCM
      DEFINE I2C_SDA_PORT = PIN_A0   ' Define SDA pin
      DEFINE I2C_SCL_PORT = PIN_A1   ' Define SCL pin
    #ENDIF
    DEFINE I2C_CLOCK 100000   ' Set I2C clock frequency to 100 kHz
    
    
    ' Define constants
    ADS1115_ADDRESS   CON   $48   ' I2C address of ADS1115 (A5 and A4 connected to GND)
    CONFIG_REG        CON   $01   ' Address of the configuration register
    CONVERSION_REG    CON   $00   ' Address of the conversion register
    
    
    ' Define variables
    Data_MSB          VAR   BYTE
    Data_LSB          VAR   BYTE
    ConversionResult  VAR   WORD
    Voltage           VAR   FLOAT
    
    
    ' Initialize I2C communication
    I2CWRITE ADS1115_ADDRESS, [CONFIG_REG, $C3, $83] ' Set configuration for continuous conversion mode
    
    
    ' Main loop
    DO
      ' Request a conversion
      I2CWRITE ADS1115_ADDRESS, [CONFIG_REG, $C3, $83] ' Start a new conversion
      
      ' Wait for conversion to complete
      PAUSE 50   ' Adjust the delay based on your requirements
      
      ' Read conversion result
      I2CREAD ADS1115_ADDRESS, [CONVERSION_REG], Data_MSB, Data_LSB
      ConversionResult = MAKEWORD(Data_MSB, Data_LSB)
    
    
      ' Process the result (assuming full-scale range is 4.096V)
      Voltage = ConversionResult * 4.096 / 32768.0
      
      ' Your code to use the Voltage value as needed
      
      ' Add a delay or perform other tasks as needed
      PAUSE 1000   ' Adjust the delay based on your requirements
    LOOP

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134

    Default Re: Has anyone tried AI with PICBASIC

    Have tried many times to make it learn PBP syntax and seemed not willing to follow the manual of the compiler.

    I suppose it has its own preferences as to what links will follow and how it will learn new things. Users can interact but not purposely make it to learn from users links! And this makes sense, as we the users could make it to learn bad things, right?

    Ioannis

  3. #3
    Join Date
    Feb 2013
    Posts
    1,127

    Default Re: Has anyone tried AI with PICBASIC

    Well, at least, above code is more manageable, and only two areas need to be fixed - MAKEWORD and floating point math. I'll fix that code tomorrow, compile it and give a try on a real hardware

  4. #4

    Default Re: Has anyone tried AI with PICBASIC

    I would think that for now....... the AI can give a general computer algorithm to do a task but not exact syntax
    Last edited by amgen; - 1st January 2024 at 20:51.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134

    Default Re: Has anyone tried AI with PICBASIC

    On more common languages like C or Java thing are much better.

    Also on Arduino (which is C basically) gives a working piece of code most of the times.

    All depends on the prompt of course.

    Ioannis

  6. #6
    Join Date
    Feb 2013
    Posts
    1,127

    Default Re: Has anyone tried AI with PICBASIC

    Yes, correct.
    I have seen that with my own eyes - student asked to write a frequency meter code for arduino, she only specified that 4 digit, 7 segment display module was connected to the specified pins, and also specified a pin used as input - generated code worked directly and correctly, no modifications were needed. Both frequency measurement code, display multiplexing code - all were generated by AI.

  7. #7
    Join Date
    Feb 2013
    Posts
    1,127

    Default Re: Has anyone tried AI with PICBASIC

    Well, I tried that code and even after fixing syntax, it does not work.

    By the way, I tried to do my own code for that chip, but that also does not work - returns 64 for MSB and LSB bytes. The hardware wiring is correct, because if I remove VDD to chip, these bytes are returned as 0.

    Here's my code for it, according to chip datasheet:

    1. Write to Config register:
    – First byte: 0b10010000 (first 7-bit I2C address followed by a low R/W bit)
    – Second byte: 0b00000001 (points to Config register)
    – Third byte: 0b10000100 (MSB of the Config register to be written)
    – Fourth byte: 0b10000011 (LSB of the Config register to be written)
    2. Write to Address Pointer register:
    – First byte: 0b10010000 (first 7-bit I2C address followed by a low R/W bit)
    – Second byte: 0b00000000 (points to Conversion register)
    3. Read Conversion register:
    – First byte: 0b10010001 (first 7-bit I2C address followed by a high R/W bit)
    – Second byte: the ADS111x response with the MSB of the Conversion register
    – Third byte: the ADS111x response with the LSB of the Conversion register


    Code:
    DO
    i2cwrite i2dta, i2clk, $48,$01,[132,131] 'write config
    pause 10
    i2cwrite i2dta, i2clk, $48,$0 'convert
    pause 10
    i2cread i2dta, i2clk, $48,[data1,data2] 'read data
    serout2 portc.5,90, ["adc=",dec data1, dec data2,13,10]
    LOOP

Similar Threads

  1. conversion from picbasic to picbasic pro
    By winjohan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2011, 18:00
  2. Proton PICBASIC vs MeLabs PICBASIC
    By Fredrick in forum General
    Replies: 22
    Last Post: - 11th January 2008, 21:51
  3. PICBasic Pro vs Proton PICBasic
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd November 2006, 16:11
  4. picbasic 2.46
    By jojokatada in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th April 2005, 03:34
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 21:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts