Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Python and Java on a PIC! I just need a little help...

Status
Not open for further replies.

jumpjack

New Member
Do you think it is impossible?
I think not.
I actually think we CAN write Python and Java code for PICs!

It's just a matter of getting a python-programmable or java-programmable cellphone able to communicate with a PIC! :)
There are thousands of cellphones supporting python, and even more supporting java, just look for "pys60" and "j2me".

Connecting them to any PIC should be very easy, and I am currently studying about it: all of these phones have audio headset support, which means they can send and receive audio signals (i.e. voltage signals).

Getting them communicating with a PIC should be just a matter of enabling a PIC to "understand" if the signal is present or not on a pin; a python program on the phone will then "modulate" the sound in a proper way (i.e. you'll have to invent your protocol) to drive the PIC.

I think adding an RC filter to turn sinusoid into constant voltage, and connecting this voltage to a comparator pin in 16f628 should be all we need.

But I need some help to build this proof-of-concept project.

Where could I find a sample source to use comparators on 16f628?
I just want the PIC to light a led upon detecting an analog signal on a pin.
 
of course, but what's the matter? The result will be I can control the PIC using Python! ;)

You can do that using a PC, a phone, or anything else. This is no different from the phone or PC communicating with any other device which contain a microcontroller--which is pretty much anything you can plug into your PC or phone.

Not to shoot your idea down, but there are already digital interfaces (RS-232, USB, and a bunch of others) for communicating with a PIC or other microcontroller from a higher-level platform using a high-level language. No need to co-opt the audio on a phone to do it.


Torben
 
You can do that using a PC, a phone, or anything else. This is no different from the phone or PC communicating with any other device which contain a microcontroller--which is pretty much anything you can plug into your PC or phone.

Not to shoot your idea down, but there are already digital interfaces (RS-232, USB, and a bunch of others) for communicating with a PIC or other microcontroller from a higher-level platform using a high-level language. No need to co-opt the audio on a phone to do it.


Torben
you forgot 3 things:
- a cellphone does not require external power for at least 48 hours, and even if it is being charged, it requires a few watts
- a cellphone can be placed anywhere around rather than on a desktop
- cellphones can receive SMS :)
 
you forgot 3 things:

No, I didn't. For one thing, in the below questions, you focus on the fact that I used the term "PC", which of course was just an example. For another, you're essentially saying that I had knowledge of something you never explained: the need for portability. Your original post was about the possibility of PICs supporting Python using your idea, which is incorrect. You have now veered off onto another topic.

- a cellphone does not require external power for at least 48 hours, and even if it is being charged, it requires a few watts

A well-designed PIC or other µC circuit can easily last that long on battery power too.

- a cellphone can be placed anywhere around rather than on a desktop

This is irrelevant to your original point that the method would mean that PICs support Python in the way you describe. You are simply describing using a high-level language to interface to a lower-level device. The fact that you want to use a cell phone as a cut-rate wireless modem doesn't mean anything in that context.

- cellphones can receive SMS :)

So can PICs.

It appears that your point was essentially that you can use Python to send SMS messages to a cell phone, which relays the messages in some form to a microcontroller. This is not a new idea.


Torben
 
Let me know which PIC you think you can put a Python or Java interpreter into. I'd be willing to wager that it would be a tough proposition. I'd also like to know which language you think the interpreter would be written in. Arrrrgh....assembly language anyone?
 
Ok guys, you don't like my idea and taht's all, but please stop bothering me with "it's an old idea", "you could do it in a better way just buy googling&studying for 3 months", "it's useless", "it's impossible, python can't run on PIC"...

I'll be soon able to drive my PICs by means of a python or java program, and that's all. ;)
 
Last edited:
Which PIC do you tink will meet your requirements? That is still the puzzler.
 
So Jack, why don't you take any pic that works, prototype your idea and report back here. I'd like to see what you come up with.
 
Hey, I did it! :)
Now my PIC gets triggered by an audio tone played by the phone!!

https://it.youtube.com/watch?v=ohD0ucjRHDU

Sorry for very poor quality of video...

This is my silly source:
Code:
; PHONE2PIC program
; This program interfaces a cellphone to a pic by means of cellphone
; audio output: upon detecting any signal present on the pin
; connected to the cellphone headset audio output, a led is lit.
;
;
; Just a proof-of-concept: use this source to write a program which allow
; driving an high current relais to be able to drive any equipment by SMS
; (you'll need a proper program running on the cellphone).
;
; ****** Comparatore settings ******
; Comparator pins RA3 to RA0 (4 pins)
; Set comparators mode by settings bits CM2:CM0 in CMCON register:
; CM2:CM0 = 010 : pin RA0 is input, bit C1OUT (bit 6) in CMCON is output, 
; internal Vref is reference voltage.
; Voltage Reference module must be set up by setting VRCON register:
; VRCON = 1010.0110
;         |||| |||'-- VR0 \
;         |||| ||'--- VR1  \
;         |||| |'---- VR2  / Vref = VR*Vdd/24 if Vrr = 1
;         |||| '----- VR3 /  Vref = Vdd/4 + VR*Vdd/32 if Vrr = 0
;         |||'------- n/a
;         ||'-------- Vrr     Set divisions
;         |'--------- VRoe    Send output to RA2 if enabled
;         '---------- VRen    Enable Vref circuit.

  PROCESSOR   16F628A
  RADIX       DEC
  INCLUDE     "P16F628A.INC"
    ;__CONFIG    11110100010000B
; Configuration is:
;   Master Clear pin is disabled (used as input)
;   Code Protection is OFF
;   Watchdog Timer is ON
;   Oscillator is Internal RC
    __config  _MCLRE_OFF & _CP_OFF & _WDT_ON & _INTRC_OSC_NOCLKOUT

  cblock 	0x20 	;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb 			;used in delay routine
	endc

C1OUTMASK   	Equ b'01000000'		;Comparator1 output bit

  ORG	0x0000
	GOTO	START
	ORG	0x0004
	GOTO	START
    
START
    bcf	STATUS,RP0 ; You must be in Bank 0 to access CMCON.
    movlw	b'00000010'		; enable comparators by setting CM2:CM0 == 010 (internal reference)
;           |||||||'--  \  Set comparator mode:
;           ||||||'---     '010' means "use internal voltage reference
;           |||||'----  /
;           ||||'-----  CIS = 0 => Comp1 input is from RA0
;           |||'------  C1INV: invert Comp1 result (DISABLED)
;           ||'-------  C2INV: invert Comp2 result(DISABLED)
;           |'--------  ****** C1OUT: output of Comp1 ******* <<<=====----
;           '---------  C2OUT: output of Comp2  (NOT USED)    
    movwf	CMCON		      ; Comparator input is RA0.  See 16F628A datasheet section 10.0
    
    
    bsf	STATUS,RP0 ; You must be in Bank 1 to access VRCON.
; ********** Set reference value ********* <<<====----    
    movlw b'10100001'   ; Enable Vref module and set Vref ======== 0110 = 6  => 1/4 Vdd = 0.125 V
;           |||||||'-- VR0 \
;           ||||||'--- VR1  \
;           |||||'---- VR2  / if Vrr = 1:  Vref = VR*Vdd/24 
;           ||||'----- VR3 /  if Vrr = 0:  Vref = Vdd/4 + VR*Vdd/32 
;           |||'------ n/a
;           ||'------- Vrr     Set divisions scale
;           |'-------- VRoe    Send output to RA2 if enabled
;           '--------- VRen    Enable Vref circuit.
    movwf VRCON         ; See 16F628A datasheet section 11.0
    call DELAY ;Time to settle down VREF
    
    
    BSF         STATUS,RP0    ; Bank 1 
    CLRF        TRISB         ; PORT B is output
    BCF         STATUS,RP0    ; Bank 0
    
    

    bcf	STATUS,RP0 ; Must be on Bank 0 to access CMCON (comparator results)
    
L_CHECK    
        CLRWDT
        movf CMCON,w
        andlw C1OUTMASK			      ; check C1OUT bit
        btfsc STATUS,Z		
        goto L_ACK                ; Comparator = 1 => Light led
        goto L_NOTH               ; Comparator = 0 => loop     
L_ACK        
        MOVLW       11100000B       
        MOVWF       PORTB        
        goto L_CHECK 
L_NOTH
        MOVLW       00000000B   
        MOVWF       PORTB        
        goto L_CHECK        
        

DELAY	movlw	d'250'			;delay 250 ms (4 MHz clock) to make run faster or slower change the d'250' setting
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	return
	
    END
 
anyone with analog input or comparator.
What do those peripherals have to do with running a Java or Python interpreter? Not much I'll venture a guess. It is the amount of program memory and the amount of data memory that are key indicators of the feasibility of realizing your goal. They are different on a Harvard arhitecture like the PIC16 family.

A quick check on source forge reveals that Python is written in C++ and Python. So I guess the first hurdle is to get a legitimate C++ compiler for the PIC family of interest. So here is me throwing down the gauntlet. If you can find a python interpreter that runs on any member of the PIC family I will be one surprised puppy.
 
Last edited:
Most of PIC programs are just a matter of turning on a pin depending on the status of another pin.
Once my SW will be ready (HW is already there: a PIC connected to GND and Vcc is all we need!), we'll be able to do this just by properly programming in python/java/flashlite/whatelse-runs-on-a-phone :D

Is out there any ready-made source to identify the frequency of an analog signal with a PIC?
 
Tone detection using a PIC which could be useful to you:
**broken link removed**
If you really want to use Java and HTML on a PIC (Well served up by a PIC and running on something else like a web enabled phone) then look into an ethernet interface:
**broken link removed**
and you can control the PIC from anywhere in the world where internet access is available.
 
Tone detection using a PIC which could be useful to you:
**broken link removed**
If you really want to use Java and HTML on a PIC (Well served up by a PIC and running on something else like a web enabled phone) then look into an ethernet interface:
**broken link removed**
and you can control the PIC from anywhere in the world where internet access is available.
thanks for links, but they are too complex, I'm looking for something very simple.
I just found out that all I need in mi phone2pic circuit is ONE component: the PIC!
I connected phone audio output directly to 16f628a comparator, and it was able to detect signal and to light a led when the signal is present.

Determining signal frequency should be just a matter of counting how many times signal goes high in a second.

Any idea about how I can simulate an analog sinusoidal input in MPLAB PIC simulator?
 
Status
Not open for further replies.

Latest threads

Back
Top