-
Re: Has anyone tried AI with PICBASIC
Quote:
I don't see any issues with IC address - it is done according to datasheet.
Quote:
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
when has a 7 bit i2c slave address ever worked in pbp?
-
Re: Has anyone tried AI with PICBASIC
Does manual say anywhere that it won't ?
-
Re: Has anyone tried AI with PICBASIC
When manual says byte sized variables, it is implied 8 bits I guess.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
So this IC can't be used with PBP ?
-
Re: Has anyone tried AI with PICBASIC
I cannot see how one can send only 7 bits when the integrated command is set to send 8 bits...
I think you have to make your own routine, maybe in assembly.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
Quote:
I think you have to make your own routine, maybe in assembly.
or convert the 7 bit address to an 8 bit address as i have explained multiple times in other posts
-
Re: Has anyone tried AI with PICBASIC
just spotted this gem on the arduino forum
Quote:
you need to know better than the AI in order to know that the solution offered by the AI is wrong
-
Re: Has anyone tried AI with PICBASIC
It makes perfectly sense!
One cannot blindly trust the machine. The replies depend very much on the prompt anyway. So, if you do not how to ask or what to ask, then you cannot expect magic to happen, right?
Ioannis
-
Re: Has anyone tried AI with PICBASIC
I would say, that for relatively simple coding routines, PBP knowledge of AI had been improved, but just when you ask something more complex, you'll get this:
can you create picbasic pro code which will draw a circle on a LCD screen, which uses ST7920 controller?
(I'm omitting some DEFINE's and other non-relevant stuff)
Code:
' Initialize LCDLCDINIT' Main program loopMain: ' Clear display LCDOUT $01 ' Set cursor to home LCDOUT $02 ' Set display to graphics mode LCDOUT $3F ' Set start line to 0 LCDOUT $40 ' Set display start line LCDOUT $C0 ' Draw circle CIRCLE 64, 32, 20
-
Re: Has anyone tried AI with PICBASIC
It makes very human-like errors.
For example, I asked it how to convert the time from GPS receiver, which simply outputs digits in ASCII format to raw decimal digits, and here's the code:
Code:
hours = (time_data[0] - "0") * 10 + (time_data[1] - "0")minutes = (time_data[2] - "0") * 10 + (time_data[3] - "0")
It assumed that "0" is the raw value of ASCII digit "0" :) In ZX Spectrum Basic it would be VAL("0"), but in PBP there's not VAL...
Interesting, is there any other syntax of basic, which treats "0" as it's decimal value in ASCII table?
-
Re: Has anyone tried AI with PICBASIC
Minus "0" means in fact -48.
Maybe this is what is needed by the rest of the program. With just this line I am not sure if it is right or wrong.
As always, answer depends on the prompt. If you give enough and precise info you will get better response.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
yes sure, I changed "0" to 48 and everything works fine.
The question is, from where it took "0", is there any programming language that can make ASCII to decimal conversion that way?
-
Re: Has anyone tried AI with PICBASIC
In every language "0" is equal to 48 dec. or "1" equal to 49, etc.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
What do you mean you changed "0" to 48 and it worked? I'm sure it worked fine with "0".
You must stop mixing up the interpreted ZX BASIC with PBP.
In PBP lingo
48
$30
%00110000
"0"
are all representing the exact same thing, just differently for human readability.
If you were to connect to 8 LEDs to PortB of your PIC and then do PortB = x where x is any of the above they would all result in the exact same thing being displayed on the LEDs.
So, in your specific example subtracting "0" will subtract the numeric value 48 from the numeric value of the ASCII code for the digit question. This will result a numeric value equal to that of 'the digit'.
-
Re: Has anyone tried AI with PICBASIC
Quote:
The question is, from where it took "0", is there any programming language that can make ASCII to decimal conversion that way?
nearly all can do that, except that in C,C++ etc it would be '0' not "0" [single quotes is a chr 'literal' double quote is a null terminated "string" c-str]
-
Re: Has anyone tried AI with PICBASIC
I'm not mixing, but with PBP
X-"0" gives syntax error while compiling.
-
Re: Has anyone tried AI with PICBASIC
I am pretty sure it does not. Compiles just fine because "0" is in fact 48. So if X-48 compiles it will also compile X-"0".
If course to have correct results you should not mix 0 (zero) with O (capital letter O) because they have different ascii value. But all compile fine.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
I've found CoPilot to be OK for .net, but useless for PBP.
ChatGPT can be helpful, but only when used sparingly - "Write me an I2C routine to read a [chip number]".
AI has improved over the last couple of years.
-
Re: Has anyone tried AI with PICBASIC
Yes, there are definitely some improvements with ChatGPT when it comes to PBP, but still a long way to go.
Very often it has issues with syntax - it confuses PBP with Bascom or GC basic and uses operators from there.
And when you ask it to check and correct, it says - "oh, you're right, this particular statement is not supported by PBP, let me modify a code for you".
So while mostly being useless for PBP, at least it gives some direction, when I need to interface with some "fresh" hardware - syntax is usually wrong, and boundaries are not checked and code sequence is also messed, but registers/addresses usually are correct.
-
Re: Has anyone tried AI with PICBASIC
DeepSeek is much better in creating programs.
Not for a finished job of course, but helps to start.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
Well, I asked both to create a simple code - Read time from DS3231 and display it on HD44780 display.
Judge by yourself :)
Code:
' PICBasic Pro Code to Read DS3231 RTC and Display Time on LCD
' Connections:
' - DS3231: SDA -> PORTC.4, SCL -> PORTC.3
' - LCD: Connected in 4-bit mode to PORTB
' Define LCD
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
' I2C Pin Assignments
SDA VAR PORTC.4
SCL VAR PORTC.3
' Time Variables
second VAR BYTE
minute VAR BYTE
hour VAR BYTE
' DS3231 I2C Address
RTC_ADDR CON $D0 ' 7-bit address shifted left
' Convert BCD to Decimal
FUNC_BCD2DEC:
ASM
MOVF second, W
ANDLW 0x0F
MOVWF _temp1
SWAPF second, W
ANDLW 0x0F
MOVWF _temp2
MOVF _temp2, W
MOVWF second
ADDWF _temp1, F
MOVF minute, W
ANDLW 0x0F
MOVWF _temp1
SWAPF minute, W
ANDLW 0x0F
MOVWF _temp2
MOVF _temp2, W
MOVWF minute
ADDWF _temp1, F
MOVF hour, W
ANDLW 0x0F
MOVWF _temp1
SWAPF hour, W
ANDLW 0x0F
MOVWF _temp2
MOVF _temp2, W
MOVWF hour
ADDWF _temp1, F
ENDASM
RETURN
' Read Time from DS3231
Read_Time:
I2CWRITE SDA, SCL, RTC_ADDR, 0, [0] ' Set register pointer to 0
I2CREAD SDA, SCL, RTC_ADDR, [second, minute, hour] ' Read time
GOSUB FUNC_BCD2DEC ' Convert BCD to decimal
RETURN
' Initialize LCD
PAUSE 500
LCDOUT $FE, 1 ' Clear LCD
LCDOUT $FE, $80, "Time: "
' Main Loop
Main:
GOSUB Read_Time ' Read DS3231 time
LCDOUT $FE, $C0, DEC2 hour, ":", DEC2 minute, ":", DEC2 second ' Display time
PAUSE 1000 ' Wait 1 second
GOTO Main
;
Code:
' PICBASIC PRO code to read time from DS3231 and display on HD44780 LCD
' Define PIC microcontroller (e.g., PIC16F877A)
#CONFIG
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
#ENDCONFIG
' Define LCD pins
DEFINE LCD_DREG PORTD ' LCD data port
DEFINE LCD_DBIT 4 ' Starting data bit (D4)
DEFINE LCD_RSREG PORTE ' RS pin port
DEFINE LCD_RSBIT 0 ' RS pin bit
DEFINE LCD_EREG PORTE ' Enable pin port
DEFINE LCD_EBIT 1 ' Enable pin bit
' Define I2C pins
DEFINE I2C_SCL PORTB, 1 ' SCL pin (RB1)
DEFINE I2C_SDA PORTB, 2 ' SDA pin (RB2)
' Include necessary libraries
INCLUDE "DS3231.bas" ' DS3231 I2C RTC library
INCLUDE "LCD.bas" ' HD44780 LCD library
' Variables
Dim second As Byte
Dim minute As Byte
Dim hour As Byte
Dim day As Byte
Dim month As Byte
Dim year As Byte
' Initialize LCD
LCDOUT $FE, $01 ' Clear LCD
LCDOUT $FE, $0C ' Turn on display, no cursor
' Main loop
Main:
' Read time from DS3231
DS3231_ReadTime hour, minute, second
' Display time on LCD
LCDOUT $FE, $80, "Time: ", DEC2 hour, ":", DEC2 minute, ":", DEC2 second
' Wait for 1 second
PAUSE 1000
' Repeat
GOTO Main
-
Re: Has anyone tried AI with PICBASIC
-
Re: Has anyone tried AI with PICBASIC
It is important to know also the prompt given since it plays crucial role for the result.
On deepseek, and on my second attempt, I had to ask for the correct syntax regarding variables and config settings. So that time it got it correct while ChatGPD had really difficulties correcting the errors.
But asking for Tiananmen Square was a failure!
Ioannis
-
Re: Has anyone tried AI with PICBASIC
It does not matter, since none of code works.
Sometimes ChatGPT makes really funny moves - Once it created a new type of variable - "svar" which is not in PBP, I asked, what is this - so it replied, "Yes, this is a new type of variable, I've invented it for convience", "but such variable is not supported by picbasic pro?", "Yes I know, this is very sad, below is the code which works without svar variable" (and that code was not compiling anyways).
-
Re: Has anyone tried AI with PICBASIC
Here's a working code, written by ChatGPT, which allows to control playback of DY-SV17F and similar "DY" series mp3 modules. These modules provide far better audio quality, no noise and cracking, compared to more common, "Dfplayer" type of modules, and also, they have 4mb of onboard flash (and also MicroSD and USB flash support), which is quite handy, when you need to design an announcement or counter system.
This code took multiple iterations - it was not compiling initially because it used Proton Basic statements randomly. It was figured out. Code compiled, but not working. After reading the datasheet, I've figured out that it was not sending "source selection" statement. After pointing it to that, it took about 20 minutes to generate the code. It was still far from perfect, because "main" part was at the bottom, so module was confused. Now I've moved manually the "Main" code to the proper place and yay, it works!
The moral of story? - It coded a lot of code, which most likely I would never be able to write, considering my limited skills, but until I suggested what is wrong and needs to be fixed, it was struggling with the working code, despite making several attempts.
Code:
' Use software UART on a chosen pin
MP3_TX VAR PORTB.1 ' pick your PIC output pin
BAUD9600 CON 84 ' 9600 baud, N,8,1 for SEROUT2
' === Constants from DY-SV17F datasheet ===
USB CON $00
TF_CARD CON $01
FLASH CON $02
' Command IDs
CMD_PLAY CON $02
CMD_PAUSE CON $03
CMD_STOP CON $04
CMD_PREV CON $05
CMD_NEXT CON $06
CMD_PLAY_SPECIFIC CON $07
CMD_SWITCH_DEVICE CON $0B
CMD_VOL_SET CON $13
' === Variables ===
dyCmd VAR BYTE
dyLen VAR BYTE
dyBuf VAR BYTE[8]
i VAR BYTE
sumW VAR WORD
crc VAR BYTE
track VAR WORD
hiB VAR BYTE
loB VAR BYTE
vol VAR BYTE
' --- Example main ---
Main:
PAUSE 500
GOSUB DY_SelectDeviceFlash ' set source = FLASH
vol = 20
GOSUB DY_SetVolume
track = 1
GOSUB DY_PlayTrack
PAUSE 5000
GOSUB DY_Pause
PAUSE 1500
GOSUB DY_Play
PAUSE 3000
GOSUB DY_Stop
END
' --- Low-level: send DY-SV17F packet (AA, cmd, len, data..., crc) ---
DY_Send:
sumW = 0
SEROUT2 MP3_TX, BAUD9600, [$AA]
sumW = sumW + $AA
SEROUT2 MP3_TX, BAUD9600, [dyCmd]
sumW = sumW + dyCmd
SEROUT2 MP3_TX, BAUD9600, [dyLen]
sumW = sumW + dyLen
IF dyLen > 0 THEN
FOR i = 0 TO dyLen-1
SEROUT2 MP3_TX, BAUD9600, [dyBuf[i]]
sumW = sumW + dyBuf[i]
NEXT
ENDIF
crc = sumW & $FF
SEROUT2 MP3_TX, BAUD9600, [crc]
PAUSE 10
RETURN
' --- High-level helpers ---
DY_SelectDeviceFlash: ' Switch to internal FLASH (02)
dyCmd = CMD_SWITCH_DEVICE
dyLen = 1
dyBuf[0] = FLASH
GOSUB DY_Send
PAUSE 150 ' module auto-plays first track after switch
' Stop playback immediately so only source is selected:
dyCmd = CMD_STOP
dyLen = 0
GOSUB DY_Send
RETURN
DY_Play:
dyCmd = CMD_PLAY : dyLen = 0
GOSUB DY_Send
RETURN
DY_Pause:
dyCmd = CMD_PAUSE : dyLen = 0
GOSUB DY_Send
RETURN
DY_Stop:
dyCmd = CMD_STOP : dyLen = 0
GOSUB DY_Send
RETURN
DY_Next:
dyCmd = CMD_NEXT : dyLen = 0
GOSUB DY_Send
RETURN
DY_Prev:
dyCmd = CMD_PREV : dyLen = 0
GOSUB DY_Send
RETURN
DY_SetVolume: ' vol = 0..30
dyCmd = CMD_VOL_SET
dyLen = 1
dyBuf[0] = vol
GOSUB DY_Send
RETURN
DY_PlayTrack: ' track = 1..65535
hiB = track >> 8
loB = track & $FF
dyCmd = CMD_PLAY_SPECIFIC
dyLen = 2
dyBuf[0] = hiB
dyBuf[1] = loB
GOSUB DY_Send
RETURN
-
Re: Has anyone tried AI with PICBASIC
Despite the progress of AI it is evident that will not replace soon a programmer.
And for the size of projects like the one you showed, probably it is worth the time to do it yourself and expand your experience than spend time in showing AI how to do it!
My 2c.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
You could save some code by replacing 'sumW' with 'crc'
-
Re: Has anyone tried AI with PICBASIC
Well, your approach is different. I'm taking the practical route.
For example, there's an artist, who made nice clay sculpture and wants to install led light strip inside it and configure it in the way, that say, first 5 leds are green, next 10 are cyan, next 15 are red and all these slowly fade in and out. He should learn programming for that?
Nope. He'll go, buy arduino, led strip, wire them together (there's just 3 wires to be wired) and will ask AI to generate the code according to his description. So within no time, he'll have functioning device, without learning what is FIFO, ALU, DWORD vs BIT type variable and many, many unnecessary things.
-
Re: Has anyone tried AI with PICBASIC
Except when it doesn't work and they don't have the foggiest idea how to fix it.
What's worse is I see folks using AI to write code for products they sell. You should be required to label your products with this so we know what products to avoid.
-
Re: Has anyone tried AI with PICBASIC
I've been playing with OpenAI and Copilot for a while now, and my experience is that they are better at higher-level syntax languages than the curly-bracket department. That means better at Python/VB than C#, better at Swift than Objective C, and better at PICBasic than Microchip C.
My main use is Copilot in Visual Studio. Copilot is an idiot savant. Although it makes stupid mistakes, it is unbelievably productive, allowing me to churn out a week's work in a day. While code completion is much better than the old vanilla Intellisense, it's the Copilot Chat that really shines.
It's a powerful tool, use carefully.
-
Re: Has anyone tried AI with PICBASIC
So, speaking simply, AI is becoming an everyday object, and many skills will be not needed. For example, many of you know how to sharpen goose feather for ink writing? Or many of you can start fire with sticks? These "skills" are quite obsolete now, but say, 200 years ago, these were mandatory. So same with AI - it will take handle of a lot of tasks, which previously were human-only prerogative.
-
Re: Has anyone tried AI with PICBASIC
Quote:
Originally Posted by
Ioannis
Despite the progress of AI it is evident that will not replace soon a programmer.
And for the size of projects like the one you showed, probably it is worth the time to do it yourself and expand your experience than spend time in showing AI how to do it!
My 2c.
Ioannis
I agree with you. A friend of mine challenged me that he could write any code for any project I wanted with AI. I think he fails to understand that writing code involves a lot of troubleshooting and problem solving. I don't think that we are there yet with AI.
-
Re: Has anyone tried AI with PICBASIC
Quote:
Originally Posted by
rsocor01
writing code involves a lot of troubleshooting and problem solving. I don't think that we are there yet with AI.
you will be able to detect when AI is "ready",
it will cost an arm and a leg to use it
-
Re: Has anyone tried AI with PICBASIC
Another example when AI code works on PBP - Multiple ADC button reading and debouncing:
Code:
ReadButton:
TempE = 0
' Repeat check 5 times for debounce
For cnter = 1 to 5
ADCIN 0, adcval ' Read from AN0 (adjust channel if needed)
If (adcval >= 230) And (adcval <= 270) Then
TempE = 1
ElseIf (adcval >= 290) And (adcval <= 330) Then
TempE = 2
ElseIf (adcval >= 380) And (adcval <= 440) Then
TempE = 3
ElseIf (adcval >= 580) And (adcval <= 700) Then
TempE = 4
Else
TempE = 0
EndIf
' If reading doesn’t match previous stable result, reset debounce
If cnter = 1 Then
E = TempE
Else
If TempE <> E Then
E = 0
Return
EndIf
EndIf
Pause 10 ' small delay between samples
Next cnter
Return
However, it still needed tweaking, because it used counter as variable name, which is reserved word, so I've changed it to cnter and this code works and far more efficient than my own - shown below:
Code:
keyhandler:
babo:
adcin 0,adcval
if adcval<100 then goto resetvar 'reset internal debounce variables
if adcval>230 and adcval<270 then a=a+1
if adcval>290 and adcval<340 then b=b+1
if adcval>385 and adcval<440 then c=c+1
if adcval>570 and adcval<660 then d=d+1
cnter=cnter+1 'increase loop iteration counter
if cnter=100 then goto analyzer 'if enough time pressed, go to analyzer
goto babo
Analyzer:
' --- Comparison Logic ---
IF (A = B) OR (A = C) OR (A = D) OR (B = C) OR (B = D) OR (C = D) THEN
E = 5 ' Tie detected
ELSE
IF (A > B) AND (A > C) AND (A > D) THEN
E = 1 ' A is greatest
ELSEIF (B > A) AND (B > C) AND (B > D) THEN
E = 2 ' B is greatest
ELSEIF (C > A) AND (C > B) AND (C > D) THEN
E = 3 ' C is greatest
ELSEIF (D > A) AND (D > B) AND (D > C) THEN
E = 4 ' D is greatest
ELSE
E = 5 ' Safety fallback (should not reach here)
ENDIF
ENDIF
resetvar:
cnter=0
'a=0
b=0
c=0
d=0
return
-
Re: Has anyone tried AI with PICBASIC
I think the part of if-then block can be faster with smaller code size like this:
Code:
If adcval<230 then TempE=0
if adcval >= 230 Then TempE = 1
If adcval >= 290 Then TempE = 2
If adcval >= 380 Then TempE = 3
If adcval >= 580 ThenTempE = 4
if adcval > 700 then TempE = 0
But since there will be quantisizing error and the adcval may play at least one bit, this will fail most of the time:
Code:
' If reading doesn’t match previous stable result, reset debounce
If cnter = 1 Then
E = TempE
Else
If TempE <> E Then
E = 0
this part should allow a margin of at least 2 digit play for adcval.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
Quote:
Originally Posted by
richard
you will be able to detect when AI is "ready",
it will cost an arm and a leg to use it
True. Unless they have open source code like in Github. I think that eventually we will get there, but we are not there yet. Maybe the new "programmer" in the future will be the professional that can ask AI how to write very complex programming code for a complex project.
-
Re: Has anyone tried AI with PICBASIC
There are some open source AI projects, like Fooocus already. You can download and run them locally, without internet.
-
Re: Has anyone tried AI with PICBASIC
AI is just unregulated theft of intellectual property with no payment for or even acknowledgement of the source.[programming is IP and an art form too]
The AI generated result is used with no consequences for its impact and no need to even identify that it was AI generated. A brave new world
https://youtu.be/TWpg1RmzAbc
-
Re: Has anyone tried AI with PICBASIC
Quote:
Originally Posted by
richard
AI is just unregulated theft of intellectual property with no payment for or even acknowledgement of the source.[programming is IP and an art form too]
The AI generated result is used with no consequences for its impact and no need to even identify that it was AI generated. A brave new world
Very true.
My other job has to do with book publishing. Many well known publishers have sued the AI companies for this exact theft. Serious problems have risen in every aspect of intellectual property (writing, programming, art designing etc).
Ioannis
-
Re: Has anyone tried AI with PICBASIC
and that is funny thing.
Human can learn from other works and create his art, literature or music based on that - this is fine. But same not fine for AI?